Selection Box

Discussion in 'PHP' started by dean5000v, Jul 8, 2008.

  1. #1
    i was wondering does anyone know any examples of code which will basically echo all of the tables you have in your database and print them into a drop down menu, so the user can then select the table they want to update.
     
    dean5000v, Jul 8, 2008 IP
  2. Greg Carnegie

    Greg Carnegie Peon

    Messages:
    385
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You can do it the same way you would get data from single table but insted of using SELECT statement you should use:
    SHOW TABLES
    Code (markup):
     
    Greg Carnegie, Jul 8, 2008 IP
  3. nihcer

    nihcer Member

    Messages:
    30
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #3
    
    $dbServer = "localhost";
    $dbUserName = "root";
    $dbPassword = "";
    
    $dbName = "your_db";
      
    $conn = mysql_connect($dbServer, $dbUserName, $dbPassword);
    
    // select db information_schema
    mysql_select_db('information_schema', $conn);
    
    $tables = array();
    $sql="SELECT table_name FROM `TABLES` T where table_schema='$dbName';";
    $res = mysql_query($sql, $conn);
    
    $dd = "<select name=\"dbtables\">\n";
    while($t = mysql_fetch_assoc($res)) {
      $dd .= "  <option value=\"".$t['table_name']."\">".$t['table_name']."</option>\n";
    }
    $dd .= "</select>";
    
    echo $dd;
    PHP:
     
    nihcer, Jul 8, 2008 IP
  4. Vooler

    Vooler Well-Known Member

    Messages:
    1,146
    Likes Received:
    64
    Best Answers:
    4
    Trophy Points:
    150
    #4
    Standard php functions may also be used:

    mysql_list_dbs
    mysql_list_tables
    mysql_list_fields
    mysql_list_processes


    regards
     
    Vooler, Jul 8, 2008 IP