RE: [PHP] $result = mysql_query($query);
| From: | John Holmes | Date: | Sun, 15 Sep 2002 00:59:14 +0000 |
| Subject: | RE: [PHP] $result = mysql_query($query); | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-116408@lists.php.net to get a copy of this message | ||
It is personal preference, either one is "correct".
The method I gave does not require the additional call to
mysql_num_rows(). It depends if you need that information or not.
---John Holmes...
> -----Original Message-----
> From: Jeremy Wilson [mailto:jwilson@intravative.com]
> Sent: Saturday, September 14, 2002 7:53 PM
> To: 'Daniel Gosselin'; holmes072000@charter.net;
php-general@lists.php.net
> Subject: RE: [PHP] $result = mysql_query($query);
>
> The correct way to do this would be the following;
>
> $query = "SELECT * FROM TABLE WHERE THIS='THAT'";
> $res = mysql_query($query);
>
> If (mysql_num_rows($res) > 0) {
> // there are results
> }
> Else {
> // there are no results
> }
>
> -----Original Message-----
> From: Daniel Gosselin [mailto:info@protento.com]
> Sent: Saturday, September 14, 2002 12:43 PM
> To: holmes072000@charter.net; php-general@lists.php.net
> Subject: Re: [PHP] $result = mysql_query($query);
>
>
> I read on php.net that you have to use SELECT count(*)
> with if(mysql_num_rows($result) != 0) but if i use count(*)
> and i have no result to show the tile is printed with empty result so
> i'll use if($row = mysql_fetch_array($result)), work fine,
>
>
> ----- Original Message -----
> From: "John Holmes" <holmes072000@charter.net>
> To: "'DtM'" <info@protento.com>; <php-general@lists.php.net>
> Sent: Saturday, September 14, 2002 3:05 PM
> Subject: RE: [PHP] $result = mysql_query($query);
>
>
> > > $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
> >
> > OK, let's think about this. You want to show a result if rows are
> > returned... So...
> >
> > if($row = mysql_fetch_array($result))
> > {
> > do
> > {
> > //do whatever
> > }while($row = mysql_fetch_array($result));
> > }
> > else
> > { //no results }
> >
> > That'll work fine. Or use mysql_num_rows(), like others suggested.
> >
> > ---John Holmes...
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php