
正文
php下拉列表显示数据 php下拉菜单取数据库
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
PHP中怎么让一个下拉菜单的内容是从数据库读取出的数据?
首先你要select
*
from
album
where
uid=YourID
然后用while循环输出,应该是echo吧
sql="select
*
from
album
where
uid=YourID"
输出select
while循环
在循环内部输出optiontitle/option
输出/select
大概其是这样,你调试下
相关问答
Q1: PHP下拉列表菜单SELECT选定对应项后检索数据库显示数据问题
muban.php页面(前端):
!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));
?
Q2: PHP 如何把下拉列表的值 显示出来
form method="post"
select name="sex"
option value="male"男/option
option value="female"女/option
/select
input type="submit" value="提交" /
/form
php下拉列表显示数据你选择php下拉列表显示数据的是:?php echo isset($_POST['sex'])?$_POST['sex']:'男'; ?
Q3: 怎么用PHP编程让下拉框点击时出现两列数据,选中时下拉框中只能得到一列数据?
前端的下拉框代码是这样的php下拉列表显示数据:
select id="dataselect"
option value="id值1"name值1/option
option value="id值2"name值2/option
/select
你选择了name值1php下拉列表显示数据,通过获取$("#dataselect").val() 就可以得到id值了。放心,这个值的对应关系是不会出错的php下拉列表显示数据!
Q4: 如何把php查询到的值显示到下拉框中
解决思路:将查询结果,遍历赋值给下拉框的option/option即可;
//数据库查询
$list=$this-db-GetList("select * from `goods_list`");
//循环
$html="select";
foreach ($list as $item){
$html.="option value =\"{$item['cateid']}\"{$item['title']}/option";
}
$html.="/select";
echo $html;
输出结果:
php下拉列表显示数据的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于php下拉菜单取数据库、php下拉列表显示数据的信息别忘了在本站进行查找喔。








