muban.php頁面(前端):
創(chuàng)新互聯(lián)公司是一家專業(yè)提供東港企業(yè)網(wǎng)站建設(shè),專注與成都網(wǎng)站制作、成都網(wǎng)站建設(shè)、外貿(mào)營銷網(wǎng)站建設(shè)、H5技術(shù)、小程序制作等業(yè)務(wù)。10年已為東港眾多企業(yè)、政府機構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專業(yè)的建站公司優(yōu)惠進行中。
!DOCTYPE?html?PUBLIC?"-//W3C//DTD?XHTML?1.0?Transitional//EN"?""
html?xmlns=""
head
meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8"?/
title臨床醫(yī)學(xué)診斷查詢/title
script?language="javascript"
function?getinfo(obj)
{
mbstr=obj.value;
dt="mbstr="?+?mbstr;
xmlhttp=new?XMLHttpRequest();
xmlhttp.onreadystatechange=function()
{
if?(this.readyState==4??this.status==200)
{
??res=?JSON.parse(this.responseText);
document.getElementById("zhengxiang").innerHTML=res[0].YxInfo;
??document.getElementById("yijian").innerHTML=res[0].YjInfo;
}
}
xmlhttp.open("POST","mubanexec.php",true);
xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");?
xmlhttp.send(dt);
return;
}
/script
/head
body
select?name="toubu"??id="toubu"?onchange="getinfo(this)"?
option?selected="selected"頭部/option?
option頭部正常/option?
option腦萎縮/option?
option腦萎縮脫髓鞘/option
/select?
divtextarea?name="zhengxiang"??id="zhengxiang"/textarea/div
div/textareatextarea?name="yijian"??id="yijian"/textarea/div
/body
/html
mubanexec.php頁面(后臺處理):
?php
header("Content-type:?text/html;?charset=utf-8");?
$instr=$_POST["mbstr"];
$conn=new?PDO("mysql:host=localhost;dbname=pacsdata","username","userpwd");
$sth=$conn-prepare("select?YxInfo,YjInfo?from?moban?where?MbName=?");
$sth-execute(array($instr));
$res=$sth-fetchAll();
echo(json_encode($res,JSON_UNESCAPED_UNICODE));
?
比如你有一個城市表
city,有字段id和city_name,
代碼如下:
?php
$sql
=
'select
*
from
city';
$res
=
mysql_query($sql);
$cities
=
array();
while
($row
=
mysql_fetch_assoc($res)
)
{
$cities[$row['id']]
=
$row['name'];
}
?
--
請選擇城市
--
?php
foreach
(
$cities
as
$id=
$city
)
{
?
?php
echo
$city;
?
原理就是從mysql查詢出所有城市的數(shù)據(jù)并弄成一個數(shù)組$cities
,然后循環(huán)$cities,按照下拉表單的格式輸出option選項就好了
下拉框select 是html標(biāo)簽,php是要把數(shù)據(jù)循環(huán)輸出就可以了
例如
?php
$rows = array('php','mysql','nginx','fcgi');
?
select
? foreach($rows as $value):?
option?=$value?/option
? endforeach;?
/select
首先你要select
*
from
album
where
uid=YourID
然后用while循環(huán)輸出,應(yīng)該是echo吧
sql="select
*
from
album
where
uid=YourID"
輸出select
while循環(huán)
在循環(huán)內(nèi)部輸出optiontitle/option
輸出/select
大概其是這樣,你調(diào)試下