PHP - 记住从MySQL中选择下拉列表的值 [英] PHP - Remember Selected value of Dropdownlist from mysql
本文介绍了PHP - 记住从MySQL中选择下拉列表的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要记住我的下拉列表中选定的值。
无论是从java,会话还是Cookie,并在回发后选择了accordinaly。任何帮助将非常感激。
I'd like to be able to remember the selected value of my dropdownlist. Whether it be from java, a Session or Cookie and have it selected accordinaly after postback. Any help would be much appreciated.
以下是我的代码:
<select name="Name" onChange="showSelected(this.value)">
<?php
$qRtu = "SELECT ID, Name From tblOption";
$result = mysql_query($qRtu);
while ($data=mysql_fetch_assoc($result)){
?>
<option value ="<?php echo $data['ID'] ?>" ><?php echo $data['Name'] ?></option>
<?php } ?>
</select>
推荐答案
您需要放入HTML才能表单控件选择单个所选选项,沿着以下行:
You will need to put in the HTML to allow the form control to select a single selected option, something along the lines of:
<?php while ($data=mysql_fetch_assoc($result)) { ?>
<option value ="<?php echo $data['ID'] ?>" <?php if($data['ID'] == 'some value')
echo( 'selected = "selected"' ); ?> >
<?php echo $data['Name'] ?>
</option>
<?php } ?>
'some_value'
将需要从您的数据库,会话或cookie抓取,或者当您计划从中获取选择框的默认值时。
The 'some_value'
is something that you will need to grab from your database, or session, or cookie, or whereever you plan to grab the default value of the select box from.
这篇关于PHP - 记住从MySQL中选择下拉列表的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文