Jump to content

Recommended Posts

humm been awhile since iv done php and need refreshing..

 

<?php $lines = file('runningclubs.txt');
echo '<select  id="club" name="club">';
foreach($lines as $line) {
    echo '<option>'.$line.'</option>';
}
echo '</select>';?>

 

which this how could i use

<?php echo $getuserprofile['club']?>

for the users allready selected club to be allready selected?

Link to comment
https://forums.phpfreaks.com/topic/142486-select-from-drop-down-menu-db-existant/
Share on other sites

<?php 
$lines = file('runningclubs.txt');
echo '<select  id="club" name="club">';
foreach($lines as $line) {
    if ($line == $getuserprofile['club']) 
          $line = 'value="' . $line . '" SELECTED';
    else
          $line = 'value="' . $line . '"';
    echo '<option ' . $line . '>'.$line.'</option>';
}
echo '</select>';
?>

 

Should do it, given that the club index of the getuserprofile should be the line you want to be selected.

oh ek..prmiso ... it now shows me

 

value="(the value from the text file)" eg. value="1"

 

 

instead of just 1

 

I am an idiot, sorry about that.

<?php 
$lines = file('runningclubs.txt');
echo '<select  id="club" name="club">';
foreach($lines as $line) {
    $rline = $line;
    if ($line == $getuserprofile['club']) 
          $line = 'value="' . $line . '" SELECTED';
    else
          $line = 'value="' . $line . '"';
    echo '<option ' . $line . '>'.$rline.'</option>';
}
echo '</select>';
?>

 

Should work.

sadly didnt select the one from my db :S

 

Then $line and $getuserprofile['club'] have seemingly different values. If you want it to work they need to be exactly the same.

 

Maybe print them both out for debugging and see where there is a difference, vardump may help also to verify each type also.

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.