我希望使用下拉菜单从基于类别表的MySQL数据库中筛选出诊所表上的诊所名称。任何帮助..
表格代码
Category :
<?php
$con=mysqli_connect("localhost","root","","qsearch");
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error()); exit();
}
$result = mysqli_query($con, "select CategoryName from category");
echo '<select id="info" name="info">';
echo '<option value="">-select-</option>';
while ($row = mysqli_fetch_assoc($result)) {
?>
<option value="<?php echo $row['CategoryName']; ?>"><?php echo $row['CategoryName'];?>
</option>
<?php
} echo "</select>";
?>
答案 0 :(得分:0)
你可以轻松地执行此代码
<?php
$mysql_hostname = "localhost";
$mysql_user = "sayedsoft";
$mysql_password = "vPVJBmCTsxAHKsKF";
$mysql_database = "emlak";
$bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) or die("Could not connect database");
mysql_select_db($mysql_database, $bd) or die("Could not select database");
?>
并添加此功能
function optoins_forselector($db,$name,$where) {
$result_urunler = mysql_query("SELECT * FROM $db WHERE $where");
$style_ = array();
while($result_row = mysql_fetch_array($result_urunler))
{
$style_[] = '<option value="'.$result_row['id'].'">'.$result_row[$name].'</option>';
}
return $style_;}
然后添加yor html代码
<select name=""><?php foreach (optoins_forselector($db,$name,$where) as $option) {echo $option;} ?> </select>
将$ db替换为数据库名称和$ name colum name,如果您对数据库进行过滤,请为exp“WHERE id ='1'”执行此操作