PHP-使用数据库中的表名填充下拉列表
我什么都试过了,就是做不到。我需要使用数据库中表的名称创建一个下拉列表。请给我点光。谢谢大家PHP-使用数据库中的表名填充下拉列表,php,mysql,Php,Mysql,我什么都试过了,就是做不到。我需要使用数据库中表的名称创建一个下拉列表。请给我点光。谢谢大家 $str = ""; $conn = connect_bd(); $sql = "SHOW TABLES FROM $banco"; $result = $conn->query($sql); if(!$result){ $str = $str . "<option> Não foi possível fazer a consulta no banco
$str = "";
$conn = connect_bd();
$sql = "SHOW TABLES FROM $banco";
$result = $conn->query($sql);
if(!$result){
$str = $str . "<option> Não foi possível fazer a consulta no banco. </option>";
}
while ($row = $result->fetch_assoc($result)){
$str = $str . "ok";
}
$str=”“;
$conn=connect_bd();
$sql=“显示来自$banco的表格”;
$result=$conn->query($sql);
如果(!$result){
$str=$str.“没有银行顾问。”;
}
while($row=$result->fetch_assoc($result)){
$str=$str.“确定”;
}
这是一个基本的想法,您可以在数组中循环,并使用数组将每个项目的值回显到select的一个选项中。您可以尝试在数组中获取表名
$result = mysql_query("show tables"); // run the query and assign the result to $result
$tables=array();
while($table = mysql_fetch_array($result)) { // go through each row that was returned in $result
$tables[]=$table;
}
print_r($tables);
然后你可以使用这个
$tables
数组来填充你的下拉列表从中显示表格
你是否设置了$banco
?@Blinkydamo是的,这只是代码的一部分。尝试一下显示表格
是的,我使用了列值做了一个,就像你做的一样,它工作正常。问题是,我的任何“ShowTablesfrom$dbname”都在工作,我无法查询这个。我还尝试了mysql_列表_表($dbname),但仍然无法显示更多代码,如果没有看到您的代码,人们将很难提供帮助。$str=“”$conn=连接_bd()$sql=“显示来自$banco的表格”$结果=$conn->query($sql);如果(!$result){$str=$str.“error”;}而($row=$result->fetch_assoc($result)){$str=$str.“ok”;#这只是一个测试}
$result = mysql_query("show tables"); // run the query and assign the result to $result
$tables=array();
while($table = mysql_fetch_array($result)) { // go through each row that was returned in $result
$tables[]=$table;
}
print_r($tables);