Home > Backend Development > PHP Tutorial > PHP如何按照指定信息查找另一数据库中同一行的信息。

PHP如何按照指定信息查找另一数据库中同一行的信息。

WBOY
Release: 2016-06-23 14:17:02
Original
1047 people have browsed it

已建好数据库tb_xmpc,只有两列,一列是xmpc_id,一列是xmpc_expr,现在我想按照从网页中提取到的xmpc_id信息得到对应的xmpc_expr列信息,设置为默认选项,不知为何总是无法显示出查询结果,向各路大侠请教!

相应代码如下:
//查找相应批次id所对应的批次说明
$query2=mssql_query("select * from tb_xmpc where xm_pcid='$xmpc_id'");
$myrow2=mssql_fetch_array($query2);
$old_pc=$myrow2[xmpc_expr];
?>


回复讨论(解决方案)

输出$myrow2结果看看,$old_pc=$myrow2[xmpc_expr];=>  $old_pc=$myrow2['xmpc_expr'];
Copy after login

你输出的怎么还是数组啊?

$query2=mssql_query("select * from tb_xmpc where xm_pcid='$xmpc_id'");$temp=array();while($myrow2=mssql_fetch_array($query2)){    array_push($temp,$myrow2['xmpc_ecpr']);}
Copy after login

<option selected="selected"><?php foreach($temp as $val){echo $val;}?></option>
Copy after login

$old_pc 不是单个值了吗?
改成这样:

楼上各位大侠,按照给出的操作还是显示不出来预设的选项,源码粘出来劳帮我看看!

Copy after login

用得着查询两遍吗?
改成下面这样:

<select name="rexm_pcid" id="rexm_pcid">      <?php                $query2=mssql_query("select * from tb_xmpc");                           while($myrow2=mssql_fetch_array($query2)){               $selected=  $myrow2[xmpc_id]==$xmpc_id ? 'selected="selected"' : '';       ?>           <option value="<?php echo $myrow2[xmpc_id];?>" <?php echo $selected;?>><?php echo $myrow2[xmpc_expr];?></option>                            <?php                   }       ?>       </select>
Copy after login

感谢5楼,可以了!高手!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
重设项目评审批次