|
Posted by zorro on 05/19/06 16:11
and does testing merely mean running it 100 000 times and clocking it?
// using preg_replace :
$s = '
<select name="color">
<option value="">choose
<option value="red">red
<option value="green">green
<option value="blue">blue
<option value="yellow">yellow
</select>';
if($_POST)
{ $c=$_POST['color'];
$s=preg_replace('/(value="'.$c.'")/','$1 selected',$s);
}
echo $s;
// using loop :
$colors=array('red','green','blue','yellow');
echo '<select name="color">';
echo '<option value="">choose';
foreach($colors as $c){
echo '<option value="'.$c.'"';
if($_POST['color']==$c)
echo ' selected';
echo '>'.$c;
}
echo '</select>';
Navigation:
[Reply to this message]
|