php - Why does this return Resource id #2? -
possible duplicate:
how “echo” “resource id #6” mysql response in php?
i new @ php , sql , i'm trying make php page list numbers of enries in table. i'm using code returns resource id #2:
$rt=mysql_query("select count(*) persons"); echo mysql_error(); echo "<h1>number:</h1>".$rt;
because mysql ressource when mysql_query()
.
use mysql_fetch_assoc()
next row. returns array column names indices. in case it's count(*)
.
here's fix , minor improvements of snippet:
$rt = mysql_query("select count(*) persons") or die(mysql_error()); $row = mysql_fetch_row($rt); if($row) echo "<h1>number:</h1>" . $row[0];
if need rows of resultset use snippet:
while($row = mysql_fetch_assoc($rt)) { var_dump($row); }
Comments
Post a Comment