Results 1 to 6 of 6

Thread: SQL finding record count

  1. #1

    Thread Starter
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349

    SQL finding record count

    Could anyone tell me how I would find out how many records are in my table using this code:
    PHP Code:
    <?php
      $query 
    "SELECT COUNT(*) FROM table";
      
    $numrows mysql_query($query) or die("Select Failed!");
      
    $numrow mysql_fetch_array($numrows);
      echo 
    $numrow;
    ?>
    All it gives is "Array" as the output.

    Thank for any help
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  2. #2
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    try
    PHP Code:
    echo $numrow[0]; 
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  3. #3
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Code:
    <?php 
        $query = "SELECT * FROM table"; 
        $result = mysql_query($query) or die("Select Failed!"); 
        $numrows = mysql_num_rows($result);
    
        echo $numrows; 
    ?>
    mysql_num_rows() is the function that will return how many records are in a query result.

    Edit: Editted to change the SQL statement to make my code make sense.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  4. #4

    Thread Starter
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349
    There we go, thanx ober.
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  5. #5
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Nevermind. I didn't even look at your SQL statement to see that you were using COUNT(). Nevermind me.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  6. #6

    Thread Starter
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349
    Thanx too Hobo.
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

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