Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/120117-solved-echo-selected-in-pulldown/
Share on other sites

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

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

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>';

?>

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>';

?>

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.