Jump to content

[SOLVED] Can you help me Please?


Gayner

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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..

 

2ry290y.jpg

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.