How *not* to assume MySQL will return data?

From: Date: Mon, 13 May 2002 14:46:44 +0000
Subject: How *not* to assume MySQL will return data?
Groups: php.general 
Request: Send a blank email to php-general+get-97379@lists.php.net to get a copy of this message
Hiya all, Stock standard, and from most of the examples I've seen, standard MySQL lookups via PHP utlises a while look to retrieve the data. All very nice and well yes... But what if there is no data? Here's a little example of what I want to do... // Check for inportaint notices for the contact. echo "<table width=\"100%\" class=\"td\">\n"; echo " <tr>\n"; echo " <td colspan=\"2\" valign=\"top\" class=\"subhead\">\n"; echo " <b><u>Important notes:</u></b><br>\n"; echo " </td>\n"; echo " </tr>\n"; $SQL = mysql_query("SELECT MessageID, MessageTitle FROM contactmessages WHERE ContactID='" . $_SESSION['ContactID'] . "' AND MessageRead='n';"); while ($ContactMessageList = mysql_fetch_array($SQL)) { echo " <tr>\n"; echo " <td align=\"left\" valign=\"top\"><a href=\"/profile/readmsg.php?MessageID=" . $ContactMessageList['MessageID'] . "\" alt=\"Read Message\" border=\"0\"><img src=\"/lib/images/arrow.gif\" border=\"0\"></td>\n"; echo " <td align=\"left\" valign=\"top\">" . $ContactMessageList['MessageTitle'] . "</td>\n"; echo " </tr>\n"; } echo "</table>\n"; echo "<br>\n"; From this example, this "block" would be printed evertime. Whether the contact has actual messages or not. How would I go about in a instance like this, to use a MySQL check and only print the block if $SQL will actually return data ? In this case, can I do something like... if ($SQL = mysql_query("something") { print the block while (do the actualy mysql lookup) { print data } } Spanks everyone :) -- me

« previous php.general (#97379) next »