Re: mysql if empty
| From: | Davi | Date: | Mon, 09 Apr 2007 21:33:52 +0000 |
| Subject: | Re: mysql if empty | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-252370@lists.php.net to get a copy of this message | ||
Em Segunda 09 Abril 2007 18:27, Lori Lay escreveu:
> chris@aquanuke.com wrote:
> > If I search for something in mysql that returns an empty result I cant
> > get it to return
> > "No result found" always returns "Found" even though the recoed does
> > not exist...
> >
> >
> > $sql = "SELECT Client FROM booked WHERE Name = 'larry'";
> >
> > $result = mysql_query($sql);
> >
> > if ($result == "")
> > {
> > echo "No result found";
> > }
> > echo "Found";
>
> Use isset.
>
> if (!isset($result)) {
> echo "No result found";
> }...
>
> Lori
$result is set ($result = mysql_query($query))...
compare to 0 is satisfatory:
$result=mysql_query($query)
$results=mysql_num_rows($result)
if($results==0)
{
echo "no result found";
}
elseif($results<0)
{
echo "Some error? ".mysql_error();
}
else
{
//your code here
}
--
Davi Vidal
davividal@siscompar.com.br
davividal@gmail.com
--
Agora com fortune:
" I imagine bugs and girls have a dim perception that nature played a cruel
trick on them, but they lack the intelligence to really comprehend the
magnitude of it. -- Calvin"