【问题标题】:PHP populate the data from database when District is selected选择 District 时 PHP 从数据库中填充数据
【发布时间】:2012-07-22 10:42:49
【问题描述】:

请改为关注此帖子 请检查我的以下帖子 Chained multiple selects

我有这段代码,用户可以在其中选择特定的医生类别,然后选择他想要查看的地区。状态后他需要点击车站(在选定的地区) 医生>>区>>车站

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>

进程.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>"; 

}

I want the station category to be auto filled when district is selected and When a category of doctor is selected, the district has to be auto filled.

我该怎么做?我更喜欢 Javascript,因为我对此有所了解。 另外,我将所有数据都放在一个数据库中,看起来像这样

类别 |车站 |区 |姓名 |资质等

【问题讨论】:

  • 您可以使用 ajax 来满足您的要求

标签: php javascript mysql database


【解决方案1】:

Ajax + jQuery 只需几行代码即可完成。

教程在这里:Ajax+jQuery Tutorial

【讨论】:

    【解决方案2】:

    州和城市的 Ajax

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

    Please check it once this is good example

    【讨论】:

      【解决方案3】:

      国家、州和城市的演示是here

      代码是Here

      按照自己的方式自定义..

      您可以将 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 中得到的结果的部分

      【讨论】:

        猜你喜欢
        • 2018-09-11
        • 2016-04-23
        • 2013-03-04
        • 1970-01-01
        • 2016-05-27
        • 1970-01-01
        • 1970-01-01
        • 2015-01-12
        相关资源
        最近更新 更多