wkilc Posted August 17, 2008 Share Posted August 17, 2008 Hello, Is there an easy way to echo the "selected" in a plain old pull-down menu so that it "holds" the value of the most recent query? Rather than defaulting to the top item in the list? <form name="form" method="get"> <select name="subject"> <option value="index.php?subject=choral">Choral</option> <option value="index.php?subject=band">Band</option> <option value="index.php?subject=orch">Orchestra</option> </select> </form> Thank you. ~Wayne Quote Link to comment https://forums.phpfreaks.com/topic/120117-solved-echo-selected-in-pulldown/ Share on other sites More sharing options...
redarrow Posted August 17, 2008 Share Posted August 17, 2008 Is there any reason for this as it the user that on the current web site what seeing the page? if you got a database with the current entry from the drop down then yes otherwise no....... session wont help as the new user seeing the page wont have the session set to see the new entry............ the only way is using a database or a flat file to show the current drop down selected post, unless you want the current user who seleted the drop down to see the results then use a session not the database................... personaly it always good to use a database no matter what your doing unless for fun.............. recording everthink on a database when a web site is live is verry valable......... Quote Link to comment https://forums.phpfreaks.com/topic/120117-solved-echo-selected-in-pulldown/#findComment-618804 Share on other sites More sharing options...
wkilc Posted August 17, 2008 Author Share Posted August 17, 2008 Thanks... this leads me to another question. I have a single table cell on my page that should display any number of 4 subjects that a teacher may or may not teach, for example: "choral, band, orch, guitar" ...this cell will be built form a combination of 4 different columns. If I put them all in a database, in separate columns, how can I insert a comma separator, but only when there is a value to be separated? If I did this: print "<td>$choral, $band, $orch, $guitar</td>"; ... and one teacher, in his row, didn't have a value for "$band" because he doesn't teach band, and I don't want this: "choral, , orch, guitar" Thank again. ~Wayne Quote Link to comment https://forums.phpfreaks.com/topic/120117-solved-echo-selected-in-pulldown/#findComment-618813 Share on other sites More sharing options...
unrelenting Posted August 17, 2008 Share Posted August 17, 2008 Try this: <?php echo ' <form name="form" method="get"> <select name="subject">'; if (($_GET[subject] == 'choral') { echo '<option selected value="index.php?subject=choral">Choral</option>'; } else { echo '<option value="index.php?subject=choral">Choral</option>'; } if (($_GET[subject] == 'choral') { echo '<option selected value="index.php?subject=band">Band</option>'; } else { echo '<option value="index.php?subject=band">Band</option>'; } if (($_GET[subject] == 'orch') { echo '<option selected value="index.php?subject=orch">Orchestra</option>'; } else { echo '<option value="index.php?subject=orch">Orchestra</option>'; } echo ' </select> </form>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/120117-solved-echo-selected-in-pulldown/#findComment-618816 Share on other sites More sharing options...
wkilc Posted August 18, 2008 Author Share Posted August 18, 2008 Thank you very much! The makes sense. But... I'm getting this when I try to use that exact code... Parse error: syntax error, unexpected '{' ~Wayne Quote Link to comment https://forums.phpfreaks.com/topic/120117-solved-echo-selected-in-pulldown/#findComment-618843 Share on other sites More sharing options...
unrelenting Posted August 18, 2008 Share Posted August 18, 2008 Thank you very much! The makes sense. But... I'm getting this when I try to use that exact code... Parse error: syntax error, unexpected '{' ~Wayne Sorry. I snagged that from one of my scripts and missed those. Try this: <?php echo ' <form name="form" method="get"> <select name="subject">'; if ($_GET[subject] == 'choral') { echo '<option selected value="index.php?subject=choral">Choral</option>'; } else { echo '<option value="index.php?subject=choral">Choral</option>'; } if ($_GET[subject] == 'choral') { echo '<option selected value="index.php?subject=band">Band</option>'; } else { echo '<option value="index.php?subject=band">Band</option>'; } if ($_GET[subject] == 'orch') { echo '<option selected value="index.php?subject=orch">Orchestra</option>'; } else { echo '<option value="index.php?subject=orch">Orchestra</option>'; } echo ' </select> </form>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/120117-solved-echo-selected-in-pulldown/#findComment-618854 Share on other sites More sharing options...
wkilc Posted August 18, 2008 Author Share Posted August 18, 2008 BEAUTIFUL!! Thank you very much. ~Wayne Quote Link to comment https://forums.phpfreaks.com/topic/120117-solved-echo-selected-in-pulldown/#findComment-618895 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.