Re: $result = mysql_query($query);
| From: | Matt | Date: | Sat, 14 Sep 2002 16:52:48 +0000 |
| Subject: | Re: $result = mysql_query($query); | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-116388@lists.php.net to get a copy of this message | ||
> From: "DtM" <info@protento.com>
> Sent: Saturday, September 14, 2002 12:22 PM
> Subject: [PHP] $result = mysql_query($query);
> Hi,
>
> I did a query like this:
>
> $query = "SELECT * from TABLE WHERE CHAMP = 'truc' order by NO LIMIT
0,10";
> $result = mysql_query($query);
>
> what i'm trying to do is if the result is !=0 echo the result else echo
> nothing
> i tried this
>
> if($result != 0){
> ?>
> HTML here if we have result
> <?
> while($row = mysql_fetch_array($result)){?>
>
> a href="http://<?=$row[WEB];?>"
target="_blank"><?=$row[DESCRIPTION];?></a>
>
> <?php
> }
> }?>
$result will only be false when you have an error in the syntax of the sql
statement. It won't mean you have a result in the result set. If $result
is false (mysql says there's an error in the sql), you should either echo
out mysql_error() or at least log mysql_error() so you'll know what the
trouble is.
To see if you have any results use mysql_num_rows($result) or the while
logic you already have.