Hi there i need to make an array with the result from a query (numbers 1-4) I need to calculate how many occurances of each 1-4 number is in the table. Im new to this and havent much experience with arrays but ive managed to create an array and echo the results:

2 Class
3 Class
1 Class
3 Class
3 Class
2 Class
2 Class
2 Class

So i need to somehow Add the occurance of them and echo the results e.g. 4 Class 2, 1 Class 1, 3 Class 3.

If someone could please point me in the right direct that would be great.

$colname_Recordset1 = "-1";
if (isset($_SESSION['MM_Username'])) {
  $colname_Recordset1 = (get_magic_quotes_gpc()) ? $_SESSION['MM_Username'] : addslashes($_SESSION['MM_Username']);
}

mysql_select_db($database_swb, $swb);
$query = sprintf("SELECT Class FROM ships WHERE PlayerName = %s", GetSQLValueString($colname_Recordset1, "text"));
$result = mysql_query($query, $swb) or die(mysql_error());

while($row = mysql_fetch_array($result)){
	echo $row['Class']. " Class ";
	echo "<br />";
}
mysql_free_result($result);?>;

Thank You 🙂

    You could do

    SELECT count(Class),Class FROM ships WHERE PlayerName = %s GROUP BY Class

    for your query and not count it yourself =D

      Thanks for the reply. How would i ouput the results? I get an error when i echo echo $result['Class']; Nothing is outputted at all. Sorry im new to to php.

      Thanks

        print_r will show you what it looks like, that is simply print_r($result), To preserve indenation in a web browser, use the pre element

        printf('<pre>%s</pre>', print_r($result,1));
        

        And also note that you can rename identifiers in result sets

        SELECT field AS newname
        
          Write a Reply...