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;
1
  • 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 instead. Commented Sep 14, 2016 at 6:44

1 Answer 1

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;
Sign up to request clarification or add additional context in comments.

2 Comments

Pease do not advocate the deprecated mysql_* functions.
mysql is deprecated in higher php version

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.