From: Peter Brawley Date: March 28 2006 8:59pm Subject: Re: Li'l problem with count() List-Archive: http://lists.mysql.com/mysql/196266 Message-Id: <4429A3C0.4070000@earthlink.net> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=======AVGMAIL-4429A3C017B1=======" --=======AVGMAIL-4429A3C017B1======= Content-Type: multipart/alternative; boundary=------------040900020203040300030505 --------------040900020203040300030505 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Sandy, >$result = mysql_query($sql,$lnk); >... >Why this leads to 'ressource id #10' instead of the flies count ? >The query gives the actual count if I use it in a line command !! You've been fooled by your variable name. For SELECT, SHOW, DESCRIBE or EXPLAIN, mysql_query() returns a resource on success, ||for other type of SQL statements (UPDATE, DELETE etc) mysql_query() returns |TRUE| on success, and they both return |FALSE| on error. PB ----- > Hi > > > >

Flies in pot =

> > function flies(){ > $sql = 'select count(*) from flies'; > $lnk = mysql_connect('localhost','root','123456'); > $db = mysql_select_db('moar',$lnk); > $result = mysql_query($sql,$lnk); > mysql_free_result($result); > mysql_close($lnk); > return $result; > } > > > Why this leads to 'ressource id #10' instead of the flies count ? > The query gives the actual count if I use it in a line command !! > > thanks > > > > > > --------------040900020203040300030505 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Sandy,
>$result = mysql_query($sql,$lnk);
>...
>Why this leads to 'ressource id #10' instead of the flies count ?
>The query gives the actual count if I use it in a line command !!
You've been fooled by your variable name. For SELECT, SHOW, DESCRIBE or EXPLAIN, mysql_query() returns a resource on success, for other type of SQL statements (UPDATE, DELETE etc) mysql_query() returns TRUE on success, and they both return FALSE on error.

PB

-----

Hi



<p>Flies in pot = <?=flies();?> </p>

function flies(){
$sql = 'select count(*) from flies';
$lnk = mysql_connect('localhost','root','123456');
$db = mysql_select_db('moar',$lnk);
$result = mysql_query($sql,$lnk);
mysql_free_result($result);
mysql_close($lnk);
return $result;
}


Why this leads to 'ressource id #10' instead of the flies count ?
The query gives the actual count if I use it in a line command !!

thanks





  
--------------040900020203040300030505-- --=======AVGMAIL-4429A3C017B1======= Content-Type: text/plain; x-avg=cert; charset=us-ascii Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Content-Description: "AVG certification" No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.1.385 / Virus Database: 268.3.2/294 - Release Date: 3/27/2006 --=======AVGMAIL-4429A3C017B1=======--