如何用PHP获取数据库表一列的所有数据显示在下拉菜单中,如下我的代码报错,怎样解决?
<select><optionvalue=0>请选择</option><?phptry{$pdo=newPDO('mysql:host=localhost;dbname=...
<select>
<option value=0>请选择</option>
<?php
try{
$pdo = new PDO('mysql:host=localhost;dbname=school',"root","");
error_Log('hi, connected to my database.');
}catch (PDOException $e) {
die('connection failed'.$e->getMessage());
}
$pdo->query("SET NAMES 'UTF8'");
$search_course = "select dname from school";
$result = mysql_query($search_course, $pdo) or die(mysql_error());
while($row = mysql_fetch_array($result))
{
echo "<option value='$row[dname]'>$row[dname]</option>";
}
?>
</select> 展开
<option value=0>请选择</option>
<?php
try{
$pdo = new PDO('mysql:host=localhost;dbname=school',"root","");
error_Log('hi, connected to my database.');
}catch (PDOException $e) {
die('connection failed'.$e->getMessage());
}
$pdo->query("SET NAMES 'UTF8'");
$search_course = "select dname from school";
$result = mysql_query($search_course, $pdo) or die(mysql_error());
while($row = mysql_fetch_array($result))
{
echo "<option value='$row[dname]'>$row[dname]</option>";
}
?>
</select> 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询