Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 8 of 8
  1. #1
    Junior Member solar's Avatar
    Join Date
    Feb 2004
    Location
    Oxford, UK
    Posts
    6
    Member #
    5006
    Hi All,

    I cant find this anywhere in the mysql docs tonight, how do i read how many rows there are in a mysql table?

    Peter

  2.  

  3. #2
    Senior Member iphong's Avatar
    Join Date
    Mar 2003
    Location
    Arlington, VA
    Posts
    751
    Member #
    916
    Originally posted by solar
    Hi All,

    I cant find this anywhere in the mysql docs tonight, how do i read how many rows there are in a mysql table?

    Peter
    PHP Code:
    $query mysql_query("SELECT `row` FROM `table` WHERE 1");
    $total_row mysql_num_rows($query);
    echo 
    $total_row
    in query select field which contains fewest data, other wise it will cause losing mysql connection if you have lots of data.
    Vu Tuan Phong
    iPhongDesign

    http://iphong.com
    http://adstudio1.com

  4. #3
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    Would execute faster this way, cause you're retrieving less data from the MySQL server:
    PHP Code:
    $query mysql_query("SELECT COUNT(column_name) AS num_rows FROM table_name;");
    if (
    $row mysql_fetch_array($queryMYSQL_ASSOC)) {
        echo 
    $row['num_rows'];


  5. #4
    Senior Member blackbird's Avatar
    Join Date
    Jan 2004
    Location
    San Francisco, CA
    Posts
    100
    Member #
    4730
    If you're just doing it from the MySQl interface, try

    SELECT count(*) FROM table;
    http://www.pearlsgirl.com

  6. #5
    Junior Member solar's Avatar
    Join Date
    Feb 2004
    Location
    Oxford, UK
    Posts
    6
    Member #
    5006
    thanks everyone for the examples i will try them out when i get home from college.

  7. #6
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    Originally posted by blackbird
    If you're just doing it from the MySQl interface, try

    SELECT count(*) FROM table;
    COUNT(*) is a bit slower than COUNT(column_name)

  8. #7
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    In MySQL, COUNT(*) is faster when there is no WHERE clause.
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!

  9. #8
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    Filb, I didn't know that (yes, I just said that), thanks. :-D


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 03:01 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com