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>";
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.