Re: checking for 0 results?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



How about:

$sql = " ... ";
$result = mysql_query($sql);
if($row = mysql_fetch_row($result))
{
  do
  {
    //process results in $row
  }while($row = mysql_fetch_row($result);
}
else
{ //no results }

This way you don't have to make an extra call to mysql_num_rows() and it
saves you time.

---John Holmes...

----- Original Message -----
From: "Hutchins, Richard" <Richard.Hutchins@GetingeCastle.com>
To: <php-db@lists.php.net>
Sent: Friday, November 15, 2002 8:47 AM
Subject: RE:  checking for 0 results?


> Aaron was right initially:
>
> $sql = "select * from ietsfuckingfriday";
>
> $result = mysql_query($sql);
>
> $num_rows=mysql_num_rows($result);
>
> Somewhere along the line, things got convoluted, but that's how you check
> for 0 rows returned from a query.
>
> > -----Original Message-----
> > From: Snijders, Mark [mailto:Mark.Snijders@atosorigin.com]
> > Sent: Friday, November 15, 2002 8:45 AM
> > To: 'Aaron Wolski'; 'Jonathan Narong'; php-db@lists.php.net
> > Subject: RE:  checking for 0 results?
> >
> >
> > and how does $sql now gets in touch with $result????
> >
> >
> >
> >
> > Or you can skip a step like:
> >
> > $sql = "select * from ietsfuckingfriday";
> >
> > if (mysql_num_rows($result) == 0) {
> >
> > do_something();
> >
> > } else {
> >
> > do_anotherthing();
> >
> > }
> >
> > Aaron
> >
> > -----Original Message-----
> > From: Snijders, Mark [mailto:Mark.Snijders@atosorigin.com]
> > Sent: November 15, 2002 8:26 AM
> > To: 'Jonathan Narong'; php-db@lists.php.net
> > Subject: RE:  checking for 0 results?
> >
> > $sql = "select * from ietsfuckingfriday";
> >
> > $result = mysql_query($sql);
> >
> > $num_rows=mysql_num_rows($result);
> >
> > if ($num_rows==0)echo "yesss we did it";
> >
> >
> > (sorry it's friday :-)
> >
> > almost can go home :--)
> >
> >
> >
> > -----Original Message-----
> > From: Jonathan Narong [mailto:jon@binaryillusions.com]
> > Sent: vrijdag 15 november 2002 14:23
> > To: php-db@lists.php.net
> > Subject:  checking for 0 results?
> >
> >
> > maybe i'm totally not thinking straight right now, but is
> > there a way in
> > php
> > to check if 0 results are returned in a mysql query?
> >
> > for example, i have a definition database, that has a list of letters
> > the
> > user clicks on (click on the letter, and all the terms for that letter
> > pop
> > up).. but for some letters there are no terms. so i just
> > wanted to echo
> > out
> > a simple "no terms" message or something. in any case, i need to check
> > if
> > there are no results from a mysql query (an error won't be returned).
> >
> > thanks ..
> >
> > -jon
> >
> >
> >
> > --
> > PHP Database Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
> > --
> > PHP Database Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
> >
> > --
> > PHP Database Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux