Gayner Posted August 29, 2009 Share Posted August 29, 2009 Hi everyone! <select name="monkskin"> <option value="0" $i>24-7GT Default</option> <option value="1" $i1>Light Blue</option> <option value="2" $i2>Sunset</option> <option value="3" $i3>Beautiful Blue</option> <option value="4" $i4>Tan</option> <option value="5" $i5>Crazy Gray</option> <option value="6" $i6>Toxin</option> </select> And I have to use all this php code so it stays selected! ($member['monkskin']=='0')? $i = "selected":""; ($member['monkskin']=='1')? $i1 = "selected":"";($member['monkskin']=='2')? $i2 = "selected":""; ($member['monkskin']=='3')? $i3 = "selected":"";($member['monkskin']=='4')? $i4 = "selected":"";($member['monkskin']=='5')? $i5 = "selected":"";($member['monkskin']=='6')? $i6 = "selected":""; ($member['monkskin']=='7')? $i7 = "selected":""; I know there's a way so it automatically Does it.. using foreach or something? Could you please help em out on this.. Thanks.. Because I am doing alot of this and I dont like to manually do all the php code to make it stay selected.. Link to comment https://forums.phpfreaks.com/topic/172351-solved-can-you-help-me-please/ Share on other sites More sharing options...
php_joe Posted August 29, 2009 Share Posted August 29, 2009 Hi everyone! <select name="monkskin"> <option value="0" $i>24-7GT Default</option> <option value="1" $i1>Light Blue</option> <option value="2" $i2>Sunset</option> <option value="3" $i3>Beautiful Blue</option> <option value="4" $i4>Tan</option> <option value="5" $i5>Crazy Gray</option> <option value="6" $i6>Toxin</option> </select> And I have to use all this php code so it stays selected! ($member['monkskin']=='0')? $i = "selected":""; ($member['monkskin']=='1')? $i1 = "selected":"";($member['monkskin']=='2')? $i2 = "selected":""; ($member['monkskin']=='3')? $i3 = "selected":"";($member['monkskin']=='4')? $i4 = "selected":"";($member['monkskin']=='5')? $i5 = "selected":"";($member['monkskin']=='6')? $i6 = "selected":""; ($member['monkskin']=='7')? $i7 = "selected":""; I know there's a way so it automatically Does it.. using foreach or something? Could you please help em out on this.. Thanks.. Because I am doing alot of this and I dont like to manually do all the php code to make it stay selected.. Change $i to $i0 and then use this code before the <select> tag: <? if($monkskin) $i$monkskin = "selected": ?> Link to comment https://forums.phpfreaks.com/topic/172351-solved-can-you-help-me-please/#findComment-908755 Share on other sites More sharing options...
Gayner Posted August 29, 2009 Author Share Posted August 29, 2009 Hi everyone! <select name="monkskin"> <option value="0" $i>24-7GT Default</option> <option value="1" $i1>Light Blue</option> <option value="2" $i2>Sunset</option> <option value="3" $i3>Beautiful Blue</option> <option value="4" $i4>Tan</option> <option value="5" $i5>Crazy Gray</option> <option value="6" $i6>Toxin</option> </select> And I have to use all this php code so it stays selected! ($member['monkskin']=='0')? $i = "selected":""; ($member['monkskin']=='1')? $i1 = "selected":"";($member['monkskin']=='2')? $i2 = "selected":""; ($member['monkskin']=='3')? $i3 = "selected":"";($member['monkskin']=='4')? $i4 = "selected":"";($member['monkskin']=='5')? $i5 = "selected":"";($member['monkskin']=='6')? $i6 = "selected":""; ($member['monkskin']=='7')? $i7 = "selected":""; I know there's a way so it automatically Does it.. using foreach or something? Could you please help em out on this.. Thanks.. Because I am doing alot of this and I dont like to manually do all the php code to make it stay selected.. Change $i to $i0 and then use this code before the <select> tag: <? if($monkskin) $i$monkskin = "selected": ?> Isn't that the exact same thing ? lol I tryed that and it gives me: Parse error: parse error on line 1365 And im using if($monkskin) $i$monkskin = "selected": Link to comment https://forums.phpfreaks.com/topic/172351-solved-can-you-help-me-please/#findComment-908758 Share on other sites More sharing options...
trq Posted August 29, 2009 Share Posted August 29, 2009 Easiest way. $options = array('24-7GT Default', 'Light Blue', 'Sunset', 'Beautiful Blue', 'Tan', 'Crazy Gray', 'Toxin'); echo "<select name='monkskin'>"; for ($i=0;$i<=6;$i++) { if ($member['monkskin'] == $i) { echo "<option value='0' selected='selected'>{$options[$i]}</option>"; } else { echo "<option value='0'>{$options[$i]}</option>"; } } echo "</select>"; Link to comment https://forums.phpfreaks.com/topic/172351-solved-can-you-help-me-please/#findComment-908760 Share on other sites More sharing options...
Gayner Posted August 29, 2009 Author Share Posted August 29, 2009 Easiest way. $options = array('24-7GT Default', 'Light Blue', 'Sunset', 'Beautiful Blue', 'Tan', 'Crazy Gray', 'Toxin'); echo "<select name='monkskin'>"; for ($i=0;$i<=6;$i++) { if ($member['monkskin'] == $i) { echo "<option value='0' selected='selected'>{$options[$i]}</option>"; } else { echo "<option value='0'>{$options[$i]}</option>"; } } echo "</select>"; First of al, Thansk for ur code but.. The dropdown works and everything but.. When it saves it to the database.. it's already 0 the value? lol Doesn't matter which 1 I choose it saves it to my database as '0' lol weird eh? u know fix ^^? Link to comment https://forums.phpfreaks.com/topic/172351-solved-can-you-help-me-please/#findComment-908762 Share on other sites More sharing options...
trq Posted August 29, 2009 Share Posted August 29, 2009 Sorry, it should be.... for ($i=0;$i<=6;$i++) { if ($member['monkskin'] == $i) { echo "<option value='$i' selected='selected'>{$options[$i]}</option>"; } else { echo "<option value='$i'>{$options[$i]}</option>"; } } Link to comment https://forums.phpfreaks.com/topic/172351-solved-can-you-help-me-please/#findComment-908763 Share on other sites More sharing options...
Gayner Posted August 29, 2009 Author Share Posted August 29, 2009 Sorry, it should be.... for ($i=0;$i<=6;$i++) { if ($member['monkskin'] == $i) { echo "<option value='$i' selected='selected'>{$options[$i]}</option>"; } else { echo "<option value='$i'>{$options[$i]}</option>"; } } WOW Man thx! your awesome, I love this site.. u guys have the best kind of brains avaliable for me.. Thank u so much, man this works wonderful.. my gosh php is so epic especially when im getting tought by u guys thanks guys.. your pro.. god bless. if ur a christian ~_~ Link to comment https://forums.phpfreaks.com/topic/172351-solved-can-you-help-me-please/#findComment-908764 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.