与表列表填充下拉列表

问题描述:

.hey球员我如何填充下拉列表与某个数据库中的表列表?与表列表填充下拉列表

$db = mysql_select_db('thepillar'); 
$sql = "SHOW TABLES"; 
$result = mysql_query($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>'; 
} 
。我已经尝试了上述代码,但下拉列表

只充满了单词“阵列”多次取决于有多少数据库中的表的存在。

.help pls!

+2

在循环内部做一个'print_r($ tables)',看看从DB返回的内容=) – kjy112 2011-03-17 20:08:37

更换

$tables = $r; 

$tables = $r['Tables_in_thepillar']; 

还你有一个额外的echo '<option>';

循环

while($r = mysql_fetch_array($result)) 
{ 
    echo $r[0]."<br />"; 
} 

你以上变量是一个关联数组。您需要指定要在<option>标记之间输出的阵列的索引。

echo '<option>'.$tables['TABLE_NAME'].'</option>'; 

有关索引名称,请参阅print_r输出。