当选择District时,PHP将从数据库中填充数据

PHP populate the data from database when District is selected

本文关键字:数据库 填充 数据 PHP 选择 District      更新时间:2024-01-14

请关注这篇文章,请查看我的以下文章链式多选

我有一个代码,用户可以在其中选择特定类别的医生,然后选择他想要查看的地区。状态后,他需要单击(所选地区的)工作站医生>>地区>>站

Here is the code 
<html>
<body>
<form action="process.php" method="post">
<select name="cat">
<?php
$sql="select distinct Category from doctors order by Category asc";
$query=mysql_query($sql);
while($row=mysql_fetch_array($query))
{
echo "<option value='{$row[Category]}'>{$row[Category]}</option>";
}
?>
</select>
<select name="station">
<?php
$sql_1="select distinct Station from doctors order by Station asc";
$query_1=mysql_query($sql_1);
while($row=mysql_fetch_array($query_1))
{
echo "<option value=".$row[Station].">".$row[Station]."</option>";
}
?>
</select>
<input name="C" type="submit" />
</form>
</body>
</html>

Process.php

$mySqlStm ="SELECT Name FROM doctors WHERE Category='$myValue' and Station='$myStation'";
$result2 = mysql_query($mySqlStm) or die("Error:mysql_error()"); 
if(mysql_num_rows($result2) == 0){ 
echo("<br/>no records found"); 
} 
ELSE 
{ 
echo "<table border='1'>"; 
//ECHO THE RECORDS FETCHED
while($row = mysql_fetch_array($result2)) 
{ 
echo "<tr>"; 
//echo "<td>" . $row['Station'] . "</td>"; 
echo "<td>" . $row['Name'] . "</td>" ; 
//echo "<td>" . $row['Phone 1'] . "</td>"; 
//echo "<td>" . $row['Mobile'] . "</td>"; 
}

我希望当选择地区时自动填写车站类别,当选择医生类别时,必须自动填写地区。

我该怎么做?我更喜欢Javascript,因为我对它略知一二。此外,我在一个数据库中有所有的数据,它看起来像这个

类别|车站|地区|名称|资质等

Ajax+jQuery将在几行代码中为您做到这一点。

这里的教程:Ajax+jQuery教程

Ajax用于州和城市

从这里你可以得到医生名单的想法

请检查一下,这是一个很好的例子

国家、州和城市的演示在这里

代码在这里

按照自己的方式定制。。

您可以将findCity.php中的代码更改为Process.php,也可以在js/location.js中更改代码你有:

$.ajax({
    type: "GET",
    url: "findCity.php",
    data: strURL,
    cache: false,
    success: function(d){
    $('#citydiv').show().html(d);
    }
});

#citydiv是将更改为Process.php 中得到的结果的部分