Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Aug 2005
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How many rows in the db?

    If I use $num = mysql_num_rows ($result); to show the results from the db, the figure I get is decided by the limit I have set in the mysql SELECT query.

    Is there another way to show how many records exists in the table, please? I mean, the total number of files in the db regardless of how may I draw out?

  • #2
    Regular Coder devinemke's Avatar
    Join Date
    Dec 2004
    Location
    NYC
    Posts
    443
    Thanks
    0
    Thanked 12 Times in 11 Posts
    Code:
    SELECT COUNT(*) FROM table

  • #3
    Regular Coder
    Join Date
    Jun 2005
    Posts
    804
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You'll need to run a separate query for the total results, but the FOUND_ROWS() function is an efficient way to do it:

    Code:
    //query 1
    SELECT
     SQL_CALC_FOUND_ROWS
     col1
    ,col2
    ,col3
    FROM
     table
    WHERE
     foo = 'bar'
    LIMIT 5;
    
    //query 2
    SELECT FOUND_ROWS();

  • #4
    New Coder
    Join Date
    Jan 2006
    Location
    UK (Britain)
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cool

    This is what i do when ever i need total rows (records):

    PHP Code:
    $total_rows mysql_result(mysql_query("SELECT COUNT(*) As num FROM table"), 0); 
    Its the same method that the phpMyAdmin uses to show you the total records

  • #5
    New Coder
    Join Date
    Aug 2005
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi devinemke, Kid Charming and VBAssassin

    Many thanks for that, and three excellent ways to do it. Very grateful, gentlemen.

    Cheers paul

  • #6
    New Coder
    Join Date
    Jan 2006
    Location
    UK (Britain)
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by zonkd
    Hi devinemke, Kid Charming and VBAssassin

    Many thanks for that, and three excellent ways to do it. Very grateful, gentlemen.

    Cheers paul
    No problem mate, im here to help.. as long as i get helped in return when i need it lol.

    Best regards,
    scott


  •  

    Posting Permissions

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