The way I'm currently getting a single value from mysql is this way:
$query = mysql_query("SELECT COUNT(*) FROM my_table");
while($row = mysql_fetch_array($query)){
$count = $row[0];
}
Is there a quicker, easier way. The code looks like overkill for one value.
SELECT COUNT(*) FROM table_name WHERE gender='MALE'
UNION
SELECT COUNT(*) FROM table_name WHERE gender='FEMALE'
Can I suggest database tables they should almost always have a primary key like this:
id INT(11) PRIMARY KEY AUTO_INCREMENT NOT NULL
And you should make a field that requires one...
If you add LIMIT 1 to the end of your sql statement it will only get one record.
But if you need all the records in the array but only want to go through the loop once you can add break(); at the end of the loop body.