快上网专注成都网站设计 成都网站制作 成都网站建设
成都网站建设公司服务热线:028-86922220

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

php下拉列表查询数据库 php下拉列表怎么设置

PHP下拉列表菜单SELECT选定对应项后检索数据库显示数据问题

muban.php页面(前端):

创新互联公司是一家专业提供东港企业网站建设,专注与成都网站制作、成都网站建设、外贸营销网站建设H5技术、小程序制作等业务。10年已为东港众多企业、政府机构等服务。创新互联专业的建站公司优惠进行中。

!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临床医学诊断查询/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));

?

php联动下拉菜单,动态获取数据库及数据库的所有表

比如你有一个城市表

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查询出所有城市的数据并弄成一个数组$cities

,然后循环$cities,按照下拉表单的格式输出option选项就好了

PHP中下拉列表框获取数据库数据

下拉框select 是html标签,php是要把数据循环输出就可以了

例如

?php

$rows = array('php','mysql','nginx','fcgi');

?

select

? foreach($rows as $value):?

option?=$value?/option

? endforeach;?

/select

PHP中怎么让一个下拉菜单的内容是从数据库读取出的数据?

首先你要select

*

from

album

where

uid=YourID

然后用while循环输出,应该是echo吧

sql="select

*

from

album

where

uid=YourID"

输出select

while循环

在循环内部输出optiontitle/option

输出/select

大概其是这样,你调试下


当前名称:php下拉列表查询数据库 php下拉列表怎么设置
当前网址:http://6mz.cn/article/dddiosp.html

其他资讯