RE: [PHP] If no record in MySQL how to?
| From: | Steve Jackson | Date: | Tue, 11 Feb 2003 12:08:04 +0000 |
| Subject: | RE: [PHP] If no record in MySQL how to? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-135185@lists.php.net to get a copy of this message | ||
Thanks Marek,
That is the solution I was looking for.
Steve Jackson
Web Developer
Viola Systems Ltd.
http://www.violasystems.com
stephen.jackson@violasystems.com
Mobile +358 50 343 5159
> -----Original Message-----
> From: Marek Kilimajer [mailto:kilimajer@webglobe.sk]
> Sent: 11. helmikuuta 2003 13:39
> To: Steve Jackson
> Cc: PHP General
> Subject: Re: [PHP] If no record in MySQL how to?
>
>
> 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 documents
> > where 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
> >
> >
> >
> >
>