How to make <option selected="selected"> set by MySql and PHP?
Posted
by Binyamin
on Stack Overflow
See other posts from Stack Overflow
or by Binyamin
Published on 2010-06-03T21:02:31Z
Indexed on
2010/06/03
21:04 UTC
Read the original article
Hit count: 231
How to make <option selected="selected">
set by MySql
and PHP
?
My code:
echo '<select>';
$tempholder = array();
$rs = mysql_query("SELECT * FROM id ORDER BY year");
$nr = mysql_num_rows($rs);
for ($i=0; $i<$nr; $i++){
//if($year=$r["year"]){ $selected=' selected="selected"'; }//doesn't work so
$r = mysql_fetch_array($rs);
if (!in_array($r['year'], $tempholder)){
$tempholder[$i] = $r['year'];
echo "<option>".$r["year"]."</option>";//<option$selected>...
}
}
unset($tempholder);
echo '</select>';
© Stack Overflow or respective owner