PHP: Set Option of Select -
i've tried lot retain selected option value on pages browse didn't succeed :(
can 1 figure out code 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 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>"; ?>
use mysql_fetch_assoc instead of mysql_fetch_array
Comments
Post a Comment