我试图从数据库中动态加载数据。就像用户单击表单中的选择按钮一样,数据将从数据库中动态加载。但问题是我必须使用 PDO。我没有得到输出,不知道出了什么问题。这是我的代码-
<tr><td><font size="+1">Region :</font></td>
<td><Select name="region" class="regionfields" id="wineRegion">
<option id="0">-- Select Region --</option>
<?php
$hostname = 'localhost';
$username = 'ovic';
$password = 'root';
try {
$dbh = new PDO("mysql:host=$hostname;dbname=winestore", $username, $password);
echo 'Connected to database<br />';
$sql = "SELECT region_name FROM region";
$stmt = $dbh->query($sql);
$obj = $stmt->fetch(PDO::FETCH_OBJ);
foreach($obj->region_name AS $W)
{?>
<option id="<?php echo $W; ?>"><?php echo $W; ?></option>
<?php
}
/*** close the database connection ***/
$dbh = null;
}
catch(PDOException $e)
{
echo $e->getMessage();
}
?>
</Select></td></tr>