I have googled and know that SELECT COUNT(*) is more efficient than mysql_num_rows. My question, is there ever a case to use mysql_num_rows.
This is what I’m looking at.
$q = "SELECT name, email FROM users WHERE state = 'Florida'"
$res = mysql_query($q) or die(mysql_error());
if(mysql_numrows($res) == '0'){
// no results, don't do anything
}
else{
while ( $row = mysql_fetch_assoc($res) ) {
echo $row["name"].' '.$row["email"];
}
}
Or does this make more sense?
$q = "SELECT COUNT(*) as ucount FROM users WHERE state = 'Florida'"
$res = mysql_query($q) or die(mysql_error());
$row = mysql_fetch_assoc($res);
if ($row["ucount"] == '0'){
// no results, don't do anything
}
else{
$q = "SELECT name, email FROM users WHERE state = 'Florida'"
$res = mysql_query($q) or die(mysql_error());
while ( $row = mysql_fetch_assoc($res) ) {
echo $row["name"].' '.$row["email"];
}
}
This is something that I have been wondering about and looking forward to a final answer.