0

I'm trying to count the number of entries in the 'classcode' column of my db which have 'class1' as the value and then convert this number into a PHP variable. Any ideas where I'm going wrong? Any help much appreciated

$result = mysql_query("SELECT COUNT(classcode) FROM playerinfo WHERE classcode='class1'");

$count = mysql_result($result, 0);

echo $count;
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
MikeMcClatchie
  • 89
  • 2
  • 11
  • Note: The `mysql_*` functions are deprecated, they have been removed from PHP 7, your code will stop working when you upgrade to that version. You should not write new code using them, use [`mysqli_*` or PDO](http://php.net/manual/en/mysqlinfo.api.choosing.php) instead. – Gerald Schneider Sep 14 '16 at 06:44

1 Answers1

1

Try this:

$result = mysql_query("SELECT COUNT(classcode) as count FROM playerinfo WHERE classcode='class1'");

$result_array = mysql_fetch_assoc($result); 
$count = $result_array['count']

echo $count;
Gerald Schneider
  • 17,416
  • 9
  • 60
  • 78
user3040610
  • 750
  • 4
  • 15