RE: [PHP] $result = mysql_query($query);

From: Date: Sat, 14 Sep 2002 23:52:31 +0000
Subject: RE: [PHP] $result = mysql_query($query);
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-116406@lists.php.net to get a copy of this message
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

« previous php.general (#116406) next »