runnerjp Posted January 26, 2009 Share Posted January 26, 2009 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 More sharing options...
gevans Posted January 26, 2009 Share Posted January 26, 2009 which this how could i use It might be me being slow but could you clarify what you're asking? Link to comment https://forums.phpfreaks.com/topic/142486-select-from-drop-down-menu-db-existant/#findComment-746598 Share on other sites More sharing options...
runnerjp Posted January 26, 2009 Author Share Posted January 26, 2009 well say i have a drop down menu looking like this 1 2 3 4 5 in my db under club i have 3 which i can echo out by using <?php echo $getuserprofile['club']?> so what would i use to show 3 allrady selected in my drop down table? Link to comment https://forums.phpfreaks.com/topic/142486-select-from-drop-down-menu-db-existant/#findComment-746608 Share on other sites More sharing options...
gevans Posted January 26, 2009 Share Posted January 26, 2009 Do you mean you want the drop down box to show the right 'number' so; <option value="1" selected>1</option> am I following? Link to comment https://forums.phpfreaks.com/topic/142486-select-from-drop-down-menu-db-existant/#findComment-746616 Share on other sites More sharing options...
premiso Posted January 26, 2009 Share Posted January 26, 2009 <?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. Link to comment https://forums.phpfreaks.com/topic/142486-select-from-drop-down-menu-db-existant/#findComment-746617 Share on other sites More sharing options...
runnerjp Posted January 26, 2009 Author Share Posted January 26, 2009 oh ek..prmiso ... it now shows me value="(the value from the text file)" eg. value="1" instead of just 1 Link to comment https://forums.phpfreaks.com/topic/142486-select-from-drop-down-menu-db-existant/#findComment-746624 Share on other sites More sharing options...
premiso Posted January 26, 2009 Share Posted January 26, 2009 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. Link to comment https://forums.phpfreaks.com/topic/142486-select-from-drop-down-menu-db-existant/#findComment-746639 Share on other sites More sharing options...
runnerjp Posted January 26, 2009 Author Share Posted January 26, 2009 sadly didnt select the one from my db :S Link to comment https://forums.phpfreaks.com/topic/142486-select-from-drop-down-menu-db-existant/#findComment-746662 Share on other sites More sharing options...
premiso Posted January 26, 2009 Share Posted January 26, 2009 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. Link to comment https://forums.phpfreaks.com/topic/142486-select-from-drop-down-menu-db-existant/#findComment-746671 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.