[RESOLVED] Question on Mysql count.
Anyone know if there's a better approach than doing
Code:
$query = "SELECT COUNT(name) FROM members";
$result = mysql_query($query) or die(mysql_error());
simply want a count of the rows really and don't need anything returned.
oh oh oh ... is it possible to do a sort of "COUNT" "WHERE" thing to only count records matching a criteria?
Re: Question on Mysql count.
(1) The return value of that query is the row count, which is what you want...
(2) select count(*) from members where a=b
Re: Question on Mysql count.
you can use the mysql_num_rows() function to see how many rows resulted from your query, though you can use MySQL's COUNT() function to do add a WHERE clause, too. If you're only looking to return the number of rows (and not any actual data from the query), COUNT() might be faster.
PHP Code:
<?php
$sql = mysql_query("SELECT id FROM table WHERE this='that' AND that='this'");
$num = mysql_num_rows($sql);
echo "There were {$num} rows returned.";
?>
Re: Question on Mysql count.
Thanks dude that works just like a brought one :wave: