jeudi 3 avril 2014

Using Selected = "Selected" PHP MySQL


Vote count:

0




I've used Selected="Selected" on SELECT that is fed by values I have written into the code, my query is how can I use it with a dynamic query from the MySQL db?


This is my written code



<label>Property Tenure</label>
<select tabindex="1" id="proptenure" name="proptenure">
<option value=""></option>
<option value="1" <?php echo ($searchtenure == '1' ? 'selected' : '')?>>Privately Owned</option>
<option value="2" <?php echo ($searchtenure == '2' ? 'selected' : '')?>>Privately Rented</option>
</select>


How can use the above type of line on my Query based SELECT



<?php echo ($searchtenure == '2' ? 'selected' : '')?>


This is an example of how I'm using SELECT from a query



<label>Fuel Type</label>
<?php $fueltype = db::getInstance()->query('SELECT * FROM lkup_fueltype');
if(!$fueltype->count()) {
echo 'Problem';
} else { ?>
<select tabindex="1" id="propertyfueltype" name="propertyfueltype">
<?php foreach ($fueltype->results() as $fueltype) { ?>
<option value="<?php echo $fueltype->PropertyFuelType; ?>"><?php echo $fueltype->PropertyFuelType; ?></option> <?php } } ?>
</select>


So how can I use the Selected="selected"?



asked 49 secs ago






Aucun commentaire:

Enregistrer un commentaire