FloridaNutz Posted August 22, 2006 Share Posted August 22, 2006 I have a mySQL database and an admin where I want to make a php file to edit entries in form mode...How do I load a default php variable to a list/menu and check boxes when i can do it with text fields?[code]<input name="barName" type="text" value="<? echo $barName ?>" size=40 maxlength=50 />[/code][code] <select name="barArea" selected="<? echo $barArea ?>" size="1"> <option value=""> -- Select One --</option> <option value="ucf">UCF </option> <option value="north">North </option> <option value="downtown">Downtown </option> <option value="disney">Disney </option> <option value="citiwalk">Citywalk </option> </select>[/code][code]<input name="barKey[]" type="checkbox" id="barKey" value="bar" /> Bar <input name="barKey[]" type="checkbox" id="barKey" value="club" /> Club <input name="barKey[]" type="checkbox" id="barKey" value="food" /> Food <input name="barKey[]" type="checkbox" value="dj" /> DJ[/code] Quote Link to comment https://forums.phpfreaks.com/topic/18266-quick-and-easy-questions/ Share on other sites More sharing options...
Barand Posted August 22, 2006 Share Posted August 22, 2006 You need to match each option value against the current value, so it's easiest to do it in a loop[code]<select name="barArea" size="1"><option value=""> -- Select One --</option> <?php $opts = array("ucf","north","downtown","disney","citiwalk") foreach ($opts as $val) { $chk = $val==$bararea ? 'selected' : ''; echo "<option value='$val' $chk> $val</option>\n"; } ?></select>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/18266-quick-and-easy-questions/#findComment-78460 Share on other sites More sharing options...
FloridaNutz Posted August 22, 2006 Author Share Posted August 22, 2006 some reason that's not working...[code] <select name="barArea" size="1"><?php $opts = array("ucf","north","downtown","disney","citiwalk") foreach ($opts as $val) { $chk = $val==$bararea ? 'selected' : ''; echo "<option value='$val' $chk> $val</option>\n"; } ?></select>[/code]unexpected T_FOREACH Quote Link to comment https://forums.phpfreaks.com/topic/18266-quick-and-easy-questions/#findComment-78575 Share on other sites More sharing options...
wildteen88 Posted August 22, 2006 Share Posted August 22, 2006 Add a semi-colon ( ; ) at the end of this line:[code=php:0]$opts = array("ucf","north","downtown","disney","citiwalk")[/code]So its:[code=php:0]$opts = array("ucf","north","downtown","disney","citiwalk");[/code]You should be fine now. Quote Link to comment https://forums.phpfreaks.com/topic/18266-quick-and-easy-questions/#findComment-78618 Share on other sites More sharing options...
FloridaNutz Posted August 22, 2006 Author Share Posted August 22, 2006 thanks, i was just about to reply that.... hense... i'm stupid lol Quote Link to comment https://forums.phpfreaks.com/topic/18266-quick-and-easy-questions/#findComment-78621 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.