populate dropdown with table list
.hey guys how can i populate a dropdown list with the list of tables from a certain database?
$db = mysql_select_db('thepillar');
$sql = "SHOW TABLES";
$result = mysql_q开发者_如何学运维uery($sql);
echo '<form method="post" id="try" action="pillar.php">';
echo 'Select Batch: ';
echo '<select name="batch" id="batch">';
echo '<option>';
while($r = mysql_fetch_assoc($result))
{
$tables = $r;
echo '<option>'.$tables.'</option>';
}
.i have tried the code above but the dropdown list is only filled with the word "Array" multiple times depending on how many tables are there in the database.
.help pls!
while($r = mysql_fetch_array($result))
{
echo $r[0]."<br />";
}
replace
$tables = $r;
with
$tables = $r['Tables_in_thepillar'];
also you got an extra echo '<option>';
above the loop
Your $tables
variable is an associative array. You need to specify which index of the array you want to output between the <option>
tags.
echo '<option>'.$tables['TABLE_NAME'].'</option>';
See the print_r
output for what the index name is.
精彩评论