Results 1 to 7 of 7

Thread: Query database for total records from all tables

  1. #1
    Join Date
    Jan 2006
    Location
    Ft. Smith, AR
    Posts
    795
    Thanks
    57
    Thanked 129 Times in 116 Posts

    Question Query database for total records from all tables

    Ok, I'm completely lost. I've tried everything I can think of, but I can't figure out how to query my database and return the total number of records (the sum of all tables)

    Any help would be greatly appreciated... I'd like to run this query via a php script so I can print the result on my site.

    Here's an image that shows you exactly what I'm talking about: http://e7t.us/database-img.png


    Thanks!
    Last edited by TheJoshMan; 03-25-2009 at 02:46 AM.
    --------------------------------------------------
    Reviews, Interviews, Tutorials, and STUFF
    --------------------------------------------------
    Home of the SexyBookmarks WordPress plugin

  2. #2
    Join Date
    Jun 2007
    Posts
    543
    Thanks
    3
    Thanked 78 Times in 78 Posts
    Blog Entries
    1

    Default

    try using mysql_num_rows. e.g.
    Code:
    $query = mysql_query("SELECT * FROM table"); 
    $number=mysql_num_rows($query);
    and incorporate that with this: http://www.ebrueggeman.com/blog/mysq...bles-in-mysql/
    Edit: added code:

    PHP Code:
    /* fill in your database name */
    $database_name "my_db";
    $number=0;
    /* connect to MySQL */
    if (!$link mysql_connect("db_host_name""username""pass")) {
      die(
    "Could not connect: " mysql_error());
    }
     
    /* query all tables */
    $sql "SHOW TABLES FROM $database_name";
    if(
    $result mysql_query($sql)){
      
    /* add table name to array */
      
    while($row mysql_fetch_row($result)){
        
    $found_tables[]=$row[0];
      }
    }
    else{
      die(
    "Error, could not list tables. MySQL Error: " mysql_error());
    }
     
    /* loop through and drop each table */
    foreach($found_tables as $table_name){
      
    $sql "SELECT * FROM $database_name.$table_name";
      if(
    $result mysql_query($sql)){
        
    $number+=mysql_num_rows($result);
      }
      else{
        echo 
    "Error finding rows in $table_name. MySQL Error: " mysql_error() . "";
      }

    Last edited by Master_script_maker; 03-22-2009 at 09:49 PM.
    [Jasme Library (Javascript Motion Effects)] My Site
    /\/\@§†ê® §©®¡þ† /\/\@|{ê®
    There are 10 kinds of people in the world, those that understand binary and those that don't.

  3. The Following User Says Thank You to Master_script_maker For This Useful Post:

    TheJoshMan (03-22-2009)

  4. #3
    Join Date
    Jan 2006
    Location
    Ft. Smith, AR
    Posts
    795
    Thanks
    57
    Thanked 129 Times in 116 Posts

    Default

    Ok, i just tried that and it's not echoing anything... not even an error to let me know there's a problem...
    --------------------------------------------------
    Reviews, Interviews, Tutorials, and STUFF
    --------------------------------------------------
    Home of the SexyBookmarks WordPress plugin

  5. #4
    Join Date
    Jun 2007
    Posts
    543
    Thanks
    3
    Thanked 78 Times in 78 Posts
    Blog Entries
    1

    Default

    well if nothing echos then there were no errors and the number was saved to the variable $number, you would have to echo that
    [Jasme Library (Javascript Motion Effects)] My Site
    /\/\@§†ê® §©®¡þ† /\/\@|{ê®
    There are 10 kinds of people in the world, those that understand binary and those that don't.

  6. The Following User Says Thank You to Master_script_maker For This Useful Post:

    TheJoshMan (03-22-2009)

  7. #5
    Join Date
    Jan 2006
    Location
    Ft. Smith, AR
    Posts
    795
    Thanks
    57
    Thanked 129 Times in 116 Posts

    Talking

    dude, you are a god... plain and simple. you've just helped ensure a timely launch of my new site...

    woot woot!
    --------------------------------------------------
    Reviews, Interviews, Tutorials, and STUFF
    --------------------------------------------------
    Home of the SexyBookmarks WordPress plugin

  8. #6
    Join Date
    Jun 2007
    Posts
    543
    Thanks
    3
    Thanked 78 Times in 78 Posts
    Blog Entries
    1

    Default

    you're welcome! glad I could help
    [Jasme Library (Javascript Motion Effects)] My Site
    /\/\@§†ê® §©®¡þ† /\/\@|{ê®
    There are 10 kinds of people in the world, those that understand binary and those that don't.

  9. The Following User Says Thank You to Master_script_maker For This Useful Post:

    TheJoshMan (03-25-2009)

  10. #7
    Join Date
    Jan 2006
    Location
    Ft. Smith, AR
    Posts
    795
    Thanks
    57
    Thanked 129 Times in 116 Posts

    Cool

    Thanks again, just wanted to share the results: http://e7t.us

    w00t w00t!
    --------------------------------------------------
    Reviews, Interviews, Tutorials, and STUFF
    --------------------------------------------------
    Home of the SexyBookmarks WordPress plugin

Bookmarks

Posting Permissions

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