PHP/MYSQL ROW COUNTING FUNCTION?

So I have a site and everything works fine and at some time in the script there is a mysql request “SELECT * FROM…” and so on and I want if the result is an empty row to display text and else display the data.At the moment no matter the return data from server it still echoes the table with results(it’s a search engine), but only the heading, as it is out of the loop cycle used to write each row of the results.I use the $query = “
Thanks,I did not know there was such a function.Now that I know about it it’s child’s play to alter my script.
about 1 year ago
$result = mysql_query($sql . “LIMIT $offset, $PerPage”) or die(‘Error, listing failed. ‘ . mysql_error());
if (mysql_num_rows($result) == 0) {
echo “No list yet”;
} else {
Here comes your FILLED result table…
It should echo ‘no list yet’.
about 1 year ago
You can use the mysql_num_rows function.
http://us.php.net/manual/en/function.mysql-num-rows.php
$numberOfRows = mysql_num_rows($result);
about 1 year ago
You definately want to use mysql_nun_rows() function for this. it returns the number of results in your query.
Of course if the number of results is zero then it gives a 0.
so what you want to do is after your mysq query is add.
$numrows = mysql_num_rows($result);
then do an if statement.
if($numrows == 0){
echo “Your query did not return any results”;
}else{
// print out your data from the dbase
}