PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
$countItems = mysql_query("SELECT COUNT(*) FROM makeMoney WHERE type='CD'");
It works
Most Requested Item: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #2' at line 1
you need to use mysql_fetch_xxx (mysql_fetch_assoc, mysql_fetch_row, etc.) in order to get a row from the result. once you have the row you can print_r it or get values from it, e.g.:
andyhoneycutt wrote:you need to use mysql_fetch_xxx (mysql_fetch_assoc, mysql_fetch_row, etc.) in order to get a row from the result. once you have the row you can print_r it or get values from it, e.g.:
Unfortunately, when running a count in a sql statement you will need to take the result and pull a row from it to get the data. counting the number of rows in the result set isn't an option because it will always be 1 for a count(*). Try the following:
$query = "SELECT COUNT(*) as mycount FROM makeMoney WHERE type='CD'";
$result = mysql_query($query);
$row = mysql_fetch_assoc($result);
$theCount = $row['mycount'];
echo "the count is: $theCount";