count multivalue field

4 posts by 2 authors in: Forums > CMS Builder
Last Post: September 12, 2022   (RSS)

Thank you in advance for your help!

I have two tables: cms_player and cms_matches

in cms_matches i have a multivalue  field  called players 

Now i want in my website i would create a list o player and count the number of matches played for each player. 

PLAYERS | MATCHES PLAYED 

Any suggestions about that?

Orazio

       <?php 
	  // mysql query
global $TABLE_PREFIX;
$query  = "select surname as surname, name as name, presenze_player as player,
count(presenze_player) as presenze
from cms_player LEFT JOIN cms_matches ON ( cms_player.num = cms_matches.presenze_player) group by surname order by presenze desc LIMIT 20";
$result = @mysql_query($query) or die("MySQL Error: ". htmlspecialchars(mysql_error()) . "\n");
$rows   = array();
while ($row = mysql_fetch_assoc($result)):
?>
<tr class="teams-match">
			<td class="hometeam">

			<?php echo $row['surname'] ?> &nbsp; <?php echo $row['name'] ?> </a><!-- // .badge-wrapper -->
		</td>
        <td class="result">><?php echo $row['presenze'] ?></td>
             <td class="result"></td>
                  <td class="result"></td>

		
		</tr><!-- // .teams-match -->
							</tbody>
						</table><!-- // .team-results-fixtures -->
					</div><!-- // .module-content -->
				</div><!-- // .module-border -->
			</div>
                 <?php endwhile ?>

This is the code i have implemented. Of course it is wrong because it is a multivalue field... 

Daniel It works!! Thank you !