PHP下拉菜单,如何通过表中的查询获取id [英] PHP Drop down menu, how get the id through query in table

查看:52
本文介绍了PHP下拉菜单,如何通过表中的查询获取id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 <?php  
// < span class =code-comment>连接数据库并运行查询

$ dbc = mysqli_connect(' localhost'' root'' '' sam_telephone');
$ get_list_sql = SELECT id,CONCAT_WS(',',l_name,f_name)AS display_name FROM
master_name;
;
$ get_list_res = mysqli_query($ dbc,$ get_list_sql);
?>

<! - 从此处开始构建下拉菜单 - >

< 表格 action = post.php 方法 = < span class =code-keyword> post
>
< 选择 名称 = sel_id >
< 选项 value = > - 选择一个 - < / option >
<! - 启动while循环以获取数组 - >
<? php
while($ x = mysqli_fetch_array($ get_list_res,MYSQLI_BOTH)){
?>
< 选项 value = <?php $ x ['id']?> name < span class =code-keyword> = <?php $ x ['id']?> > <? php echo $ x [ display_name'] ?> < / option >
<? php
}
?>
< / select >
< 输入 类型 = 提交 value = submit / >
< /表格 >
<! - 到此为止,每件事情都可以正常工作 - >


<? php

// 此部分无法正常运行,以获取ID,因为如果
/ / 我可以获取id,我可以运行查询并获得我想要的结果
// 来自此表
if(isset($ _ POST [' sel_id'])){
$ safe_id = mysqli_real_escape_string( $ mysqli,$ _POST [' sel_id']);
echo $ safe_id ;
}
?>





这是如电话目录,在下拉菜单中,它显示数据表中的人。

我想要做的是从下拉菜单中选择人物,当我点击提交按钮时,它应该显示该特定人的结果



删除了SHOUTING - OriginalGriff [/ edit]

解决方案

dbc = mysqli_connect(' localhost'' root'' '' < span class =code-string> sam_telephone');


get_list_sql = SELECT id,CONCAT_WS(',',l_name,f_name)AS display_name FROM
master_name;
;


get_list_res = mysqli_query(

<?php
//connecting to the database and running query

$dbc=mysqli_connect('localhost','root','','sam_telephone');
$get_list_sql="SELECT id, CONCAT_WS(',', l_name, f_name) AS display_name FROM 
    master_name;";
$get_list_res=  mysqli_query($dbc, $get_list_sql);
?>

<!--Building of drop down menu start from here-->

<form action="post.php" method="post">
    <select name="sel_id">
       <option value="">--Select One--</option> 
<!--Starting while loop for fetching the array-->
<?php 
while($x=mysqli_fetch_array($get_list_res,MYSQLI_BOTH)){
?>
<option value="<?php $x['id']?>" name="<?php $x['id']?>"><?php echo $x['display_name']?></option>
<?php
}
?>
</select>
    <input type="submit" value="submit"/>
    </form>
<!--Till here every thing work fine-->


<?php

// this portion is not working what i want to do its to get the id, because if 
//I can get the id, i can run the query and get the result which i want to get
// from this table
if(isset($_POST['sel_id'])){
    $safe_id = mysqli_real_escape_string($mysqli, $_POST['sel_id']);
    echo $safe_id;
}
?>



It's like telephone directory, in drop down menu, its show the people who are in the data table.
what i want to do is to select the people from drop down menu and when i click on the submit button, it should show me the result for that particular person

[edit]SHOUTING removed - OriginalGriff[/edit]

解决方案

dbc=mysqli_connect('localhost','root','','sam_telephone');


get_list_sql="SELECT id, CONCAT_WS(',', l_name, f_name) AS display_name FROM master_name;";


get_list_res= mysqli_query(


这篇关于PHP下拉菜单,如何通过表中的查询获取id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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