Results 1 to 6 of 6

Thread: select count(*) value *resolved*

  1. #1

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    select count(*) value *resolved*

    PHP Code:
    $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
    Last edited by mendhak; Feb 7th, 2003 at 12:18 AM.

  2. #2
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    I'm not sure, but I do know another way to do it:

    Code:
    $countquery="SELECT * FROM guestbook";
    
    $pagecount=mysql_num_rows(mysql_query($countquery));
    My evil laugh has a squeak in it.

    kristopherwilson.com

  3. #3
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    I just gave this a try, and it works:

    Code:
    $countquery="SELECT COUNT(*) FROM guestbook";
    $pagecount=mysql_query($countquery);
    
    $count = mysql_fetch_row($pagecount);
    
    echo $count[0];
    My evil laugh has a squeak in it.

    kristopherwilson.com

  4. #4
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    most of the time when you do count(*) you do it like so
    PHP Code:
    $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#

  5. #5

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    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?

  6. #6
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    not really. mysql_reuslts() is slower then anything else and deprecated.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width