Skip to content Skip to sidebar Skip to footer

Set Selected Value Based On Database Fetched Value

Case : Hi, Stackoverflow community. I want to set selected value on SELECT type input based on fetched value from database table column. So if db table column contain 'A', SELECT t

Solution 1:

img_type is my query result and i want img_name in drop_down

<selectid="id_name"name="photo_type"value=""><optionvalue=""></option><?phpforeach($img_typesas$row){ ?><optionvalue="<?phpecho$row->imgtype_id?>"><?phpecho$row->imgtype_name?></option><?php } ?></select>

Solution 2:

You can change your code thus:

<selectname='slPayment'><option>--</option><option " . (($query2['via']=='Cash') ? 'selected="selected"': '') .  "value='Cash'>Cash</option><option " . (($query2['via']=='Bank Transfer') ? 'selected="selected"': '') . " value='Bank Transfer'>Bank Transfer</option><option " . (($query2['via']=='Credit Card') ? 'selected="selected"': '') . " value='Credit Card'>Credit Card</option><option " . (($query2['via']=='Cheque') ? 'selected="selected"': '') . " value='Cheque'>Cheque</option><option " . (($query2['via']=='Others') ? 'selected="selected"': '') . " value='Others'>Others</option></select>

Post a Comment for "Set Selected Value Based On Database Fetched Value"