Archive for March, 2010

creating a lot of <select>s really fast

Monday, March 15th, 2010

creating a large number of identical selects can be a real pain in the posterior. This should make life a little easier.

$str="<select name='fries_with_that'>
<option value='true'>Yes</option>
<option value='false'>No</option>
</select>";

foreach($customer as $person_id=>$details) {
  $fries_with_that=$details['fries_with_that'];
  $str=str_replace("value='$fries_with_that'","value='$fries_with_that' selected",$str);
  echo str_replace("name='fries_with_that'","name='fries_with_that_$person_id'",$str);
}