php下拉列表显示数据 php获取下拉列表的值

如何把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 如何把下拉列表的值 显示出来

form method="post"

select name="sex"

option value="male"男/option

option value="female"女/option

/select

input type="submit" value="提交" /

/form

你选择的是:?php echo isset($_POST['sex'])?$_POST['sex']:'男'; ?

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

?

怎么用PHP编程让下拉框点击时出现两列数据,选中时下拉框中只能得到一列数据?

前端的下拉框代码是这样的:

select id="dataselect"

option value="id值1"name值1/option

option value="id值2"name值2/option

/select

你选择了name值1,通过获取$("#dataselect").val() 就可以得到id值了。放心,这个值的对应关系是不会出错的!

PHP下拉选择显示

恩,这个是可以做到的,但是代码不是那么简答的,这边给你提示下,你自己做下

首先,这个用跳转菜单来,数据库读取的时候如果是保存文字的那么就把文字保存在value里面  然后我每次选择一个的时候把这个名字传过去

代码我给你简单的,但是不确定跟你那能用,你拿过去参考着改下

if($_POST["name"]=="")    //首先判断类型是不是空的,如果为空则把所有的都查询出来。

{

"select * from b_goodstype";   

}

else

{

$name=$_POST["name"];

"select * from b_goodstype where class like '$name'"  ;  //否则的话根据商品类型传过来的类型查询   where class like 

}

如果还有不懂再问我 或是932628004

分享题目:php下拉列表显示数据 php获取下拉列表的值
文章链接:https://www.cdcxhl.com/article30/docpsso.html

成都网站建设公司_创新互联,为您提供品牌网站建设外贸网站建设搜索引擎优化建站公司网站设计网站建设

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

绵阳服务器托管