List:General Discussion« Previous MessageNext Message »
From:Jay Blanchard Date:March 28 2006 7:54pm
Subject:RE: Li'l problem with count()
View as plain text  
[snip]
<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 'resource id #10' instead of the flies count ?
[/snip]

Because $result is a resource in PHP, not the actual result of the
query;

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

   return $foo;
}

http://www.php.net/mysql_num_rows
Thread
Li'l problem with count()Sandy28 Mar
  • Re: Li'l problem with count()Peter Brawley28 Mar
RE: Li'l problem with count()Jay Blanchard28 Mar
  • Re: Li'l problem with count()Sandy28 Mar
  • Re: Li'l problem with count()Sandy28 Mar
RE: Re: Li'l problem with count()Jay Blanchard29 Mar