PDA

Click to See Complete Forum and Search --> : select count(*) value *resolved*


mendhak
Feb 6th, 2003, 06:14 AM
$countquery="SELECT COUNT(*) FROM guestbook";

$pagecount=mysql_query($countquery);



Now that the query has been executed, how can I access the value of the number returned by the countquery?

I do an echo $pagecount, and it returns to me:



Resource id #3

The Hobo
Feb 6th, 2003, 11:25 AM
I'm not sure, but I do know another way to do it:

$countquery="SELECT * FROM guestbook";

$pagecount=mysql_num_rows(mysql_query($countquery));

The Hobo
Feb 6th, 2003, 11:29 AM
I just gave this a try, and it works:

$countquery="SELECT COUNT(*) FROM guestbook";
$pagecount=mysql_query($countquery);

$count = mysql_fetch_row($pagecount);

echo $count[0];

phpman
Feb 6th, 2003, 03:01 PM
most of the time when you do count(*) you do it like so

$countquery="select count(*) AS total from guestbook

$pagecount=mysql_query($countquery);
$result = mysql_fetch_array($pagecount);

echo $result["total"];


that will echo out the total rows. but in your situation you can't echo out the query becasue you haven't fetched anything yet.

echo mysql_query("SELECT * FROM guestbook");

that will do the samething you have in the first post. it will return resource ID#

mendhak
Feb 6th, 2003, 09:32 PM
Hi, thanks for the responses. They did work, but I was playing around and I used this:

$somethingelse=mysql_result($pagecount,0);


Is this acceptable as well?

phpman
Feb 6th, 2003, 09:54 PM
not really. mysql_reuslts() is slower then anything else and deprecated.