RE: [PHP] Check to see if mysql_fetch_array result is empty
| From: | Michael Roger C. Bianan | Date: | Thu, 13 Mar 2003 11:45:53 +0000 |
| Subject: | RE: [PHP] Check to see if mysql_fetch_array result is empty | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-139374@lists.php.net to get a copy of this message | ||
Mike,
Use mysql_num_rows($db_query) ;
- returns no of rows in the result set.
- if none, returns 0.
Thanks,
Miches
-----Original Message-----
From: Mike Tuller [mailto:php@ce.anoka.k12.mn.us]
Sent: Wednesday, March 12, 2003 11:17 AM
To: php mailing list list
Subject: [PHP] Check to see if mysql_fetch_array result is empty
How can I check to see if a mysql_fetch_array is empty. I have a search
page, and want to have it so that when there are no matches, it returns
a message saying that there were no matches, and if there are, then
display them. Here is what I have so far to give you an idea as to what
I am trying to do.
Thanks
-----------------
$query = "SELECT * FROM software_assets WHERE $searchType LIKE
'$search' ";
$db_query = mysql_query($query, $db_connect) or die (mysql_error());
while ($row = mysql_fetch_array( $db_query ))
{
if $row = NULL
{
echo "There were no results that match your query. Please try again";
}
else
{
echo "<tr>
<td align=\"left\"><a
href=\"editsoftwareasset.php?id=$row[asset_id]\">$row[asset_id]</a></td>
</td>
<td>$row[developer]
</td>
<td align=\"center\">$row[title]
</td>
<td align=\"center\">$row[version]
</td>
<td align=\"center\">$row[platform]
</td>
</tr>\n";
}
}
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php