[英]PHP: Set Option of Select
I've tried a lot to retain the selected option value on all pages which we browse but I didn't succeed :( 我已经做了很多尝试,以在我们浏览的所有页面上保留选定的选项值,但是我没有成功:(
Can any one figure out my code what went wrong here ?? 谁能找出我的代码在这里出了什么问题?
<form name="area_form" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" >
<?php
$sql = "select *from city";
$loop = mysql_query($sql)
or die ('cannot run the query because: ' . mysql_error());
echo "<select name='areaa' onchange='window.location.href=this.value'>";
while($row = mysql_fetch_array($loop))
{
if($_POST['areaa']==$row['area'])
{
echo "<option selected VALUE=\"http://example.com\">".$row['area']."</option>";
}
else
{
echo "<option VALUE=\"http://example.com\">".$row['area']."</option>";
}
}
echo "</select>";
?>
$areaa = isset($_POST['areaa'])?$_POST['areaa']:"";
while($row = mysql_fetch_array($loop))
{
echo "<option VALUE=\"http://example.com\" $areaa==\"http://example.com\"?'selected=selected' : '' >".$row['area']."</option>";
echo "<option VALUE=\"http://example2.com\" $areaa==\"http://example2.com\"?'selected=selected' : '' >".$row['area']."</option>";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.