View Full Version : Help with Counting Results


dvduval
06-18-2005, 03:33 PM
I don't write php very often. I know this is a simple question, but I was hoping someone could help.



$query = "SELECT *
FROM student
ORDER BY student_id DESC
LIMIT 50";
$result = mysql_query($query) or die("Query failed");
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
print "<strong>Request made ".$row["date_added"]."</strong> by ".$row["student_firstname"]." ".$row["student_lastname"]." from ".$row["student_city"]." ".$row["student_zipcode"]."<br />".$row["student_message"]."<br /><br />";
}





I want say:
1) The search yielded x results
2) If no results, then print alternate message

I appreciate your time. Thank you in advance for your help. :)

Atomical
06-30-2005, 10:17 AM
mysql_num_rows($result);

if ( ($num_rows = mysql_num_rows($result)) == 0 ) {
echo 'Your query did not return any rows';
} else {
echo 'Your query returned this many rows:' . $num_rows;
}

dddougal
08-12-2005, 02:18 AM
no thanks or anything hehe