MySQL Table Names in PHP DropDown

Discussion in 'PHP' started by koolsamule, May 24, 2010.

  1. #1
    Hi Chaps,

    I'm trying to get a list of MySQL table names in a PHP/HTML Select List/Menu with the value of the Select Option being the table name.

    I have this as a starting point, but can't figure out how to get the values into the Select.

    $result = mysql_query("SHOW TABLES FROM 'DATABASE'");
    
    while($table = mysql_fetch_array($result))
      {
      $tables[]=$table;
      }
    PHP:
    Any help would be sweet. .
     
    koolsamule, May 24, 2010 IP
  2. meloncreative

    meloncreative Peon

    Messages:
    37
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Thats just adding HTML to what you have really

    echo "<select name='tables'>";
    $sql = "SHOW TABLES FROM dbname";
    $result = mysql_query($sql);
    while ($row = mysql_fetch_row($result)) {
        echo "<option value='{$row[0]}'>{$row[0]}</option>\n";
    }
    echo "</select>";
    PHP:
     
    meloncreative, May 24, 2010 IP