How to count rows from differrent database?

Discussion in 'PHP' started by geekos, Dec 12, 2010.

  1. #1
    Hi

    I have 5 database and I need to count a row from a table each database.

    Hope someone can help me.

    Thanks.
     
    geekos, Dec 12, 2010 IP
  2. shofstetter

    shofstetter Well-Known Member

    Messages:
    178
    Likes Received:
    7
    Best Answers:
    1
    Trophy Points:
    120
    #2
    you can use mysql_select_db to switch between databases and run a query on each one to get your count. if you need a combined count you can add your results after executing both queries.

    ex:
    
    mysql_select_db("database1",$con);
    $rs1 = mysql_query("SELECT COUNT(filed) FROM table1 where x=0",$con);
    mysql_select_db("database2",$con);
    $rs1 = mysql_query("SELECT COUNT(filed) FROM table2 where x=0",$con);
    
    /* code here to extract and add values from result sources  */
    
    Code (markup):
     
    shofstetter, Dec 12, 2010 IP