当选择区域时,PHP填充数据库中的数据 [英] PHP populate the data from database when District is selected

查看:187
本文介绍了当选择区域时,PHP填充数据库中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请关注此信息检查我的以下信息
链接多个选择

我有这个代码,用户选择特定类别的医生,然后选择他想要查看的区域。之后,他需要点击车站(在选定的地区)
医生>>区>>车站

 是代码
< html>
< body>
< form action =process.phpmethod =post>
< select name =cat>
<?php
$ sql =按照类别asc从医生顺序中选择不同类别;
$ query = mysql_query($ sql);

while($ row = mysql_fetch_array($ query))
{
echo< option value ='{$ row [Category]}'> {$ row [类别]}< / option>;
}
?>
< / select>
< select name =station>
<?php
$ sql_1 =选择不同的站从医生顺序由站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 =Ctype =submit/>
< / form>
< / body>
< / html>

Process.php

  $ mySqlStm =SELECT Name FROM doctors WHERE Category ='$ myValue'and Station ='$ myStation'; 

$ result2 = mysql_query($ mySqlStm)或die(Error:mysql_error());

if(mysql_num_rows($ result2)== 0){
echo(< br /> no records found);
}
ELSE
{
echo< table border ='1'>;

// ECHO 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教程


please follow this post instead Check my following post please Chained multiple selects

I have this code where a user selects the particular category of doctor and then the District in which he wants to look it. After state he needs to click the station(in the selected district) Doctor >> District >> Station

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>"; 

}

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.

How can I do it? I would prefer Javascript because I know a little bit about it. Also, i have all the data in one database it looks like this

Category | Station | District | Name | Qualification and so on

解决方案

Ajax + jQuery will do that for you in a few lines of code.

Tutorial here: Ajax+jQuery Tutorial

这篇关于当选择区域时,PHP填充数据库中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆