• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

wtf PHP+MySQL simple COUNT query not working!!!

Al Neri

Diamond Member
$query = mysql_query("SELECT COUNT(*) FROM survey1 WHERE vote=1");
$vote1=mysql_num_rows($query);
echo "$vote1";

If I run that query in PHPMYADMIN I get the value of 18

when I run it I get value of 1 for $vote1


I can't figure thisout!!?
 
$vote is being set to the number of rows returned by the query. Your query is returning a SELECT COUNT(*), which will ALWAYS return a single row.

You have two options:

1. Change the query to SELECT * or SELECT 1 so it returns the correct number of rows, or

2. (preferred) Change your $vote assignment to read the value of COUNT(*), not the number of rows (I'm not familiar with PHP so I can't help you there)
 
I have never used PHP or MySQL, so I may be out of line here. But you're doing a COUNT query. Why are you using something called mysql_num_rows? You want the value from the COUNT, not the number of rows. The number of rows returned from a COUNT is 1. 🙂
 
Back
Top