Re: If no record in MySQL how to?
| From: | Marek Kilimajer | Date: | Tue, 11 Feb 2003 11:39:08 +0000 |
| Subject: | Re: If no record in MySQL how to? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-135184@lists.php.net to get a copy of this message | ||
if there are no rows, the while condition will return false so the while block will never be executed, try
if(mysql_num_rows($link_result) ){
while($documents = mysql_fetch_array($link_result)) {
print "<table cellpadding='4'><tr><td
width='40'><img src='../images/adobepdf.gif' border='0'></td><td
width='136'><a href='$documents[url]'
class='greenlinks'>$documents[name]</a></td></tr></table>";
}
} else {
print "<table cellpadding='4'><tr><td
width='10'><img src='../images/nuoli_right_pieni.gif'
border='0'></td><td width='166'><a
href='mailto:info@violasystems.com'>No supporting documents with this
article mail us for more information</a></td></tr></table>";
}
Steve Jackson wrote:
I have a problem whereby I need to show links based on an ID which is in a MySQL DB. So if ID 1 exists I pull an array of links which are defined as belonging to ID1. This works OK. How though can I distinguish between ID's which are not in the DB. I want to display something if there are no links also and don't know what I'm doing wrong. I try to display table 1 listed below but just get nothing returned with this command. What am I doing wrong? print "<td valign='top' align='right'><img src='pictures/document_heading_blue.gif' border='0'>"; // link to documents $link_sql = "select * from documentswhere id = '$id'";$link_result = mysql_query($link_sql); while ($documents = mysql_fetch_array($link_result)) { if (!$documents["id"]) //If no ID in DB display table 1... { print "<table cellpadding='4'><tr><td width='10'><img src='../images/nuoli_right_pieni.gif' border='0'></td><td width='166'><a href='mailto:info@violasystems.com'>No supporting documents with this article mail us for more information</a></td></tr></table>"; } else //Display table with array of linked files. { print "<table cellpadding='4'><tr><td width='40'><img src='../images/adobepdf.gif' border='0'></td><td width='136'><a href='$documents[url]' class='greenlinks'>$documents[name]</a></td></tr></table>"; } } // end check for documents Steve Jackson Web Developer Viola Systems Ltd. http://www.violasystems.com stephen.jackson@violasystems.com Mobile +358 50 343 5159