Jump to content

mysql query/drop down selected


wurzel

Recommended Posts

I've got a HTML drop down box as similar to this:

 

<select name="dropdown">

<option>Option 1</option>

<option>Option 2</option>

<option>Option 3</option>

</select>

 

If I run a mysql query and get a result of "Option 3", is there anyway using PHP to give Option 3 the selected value?

Link to comment
Share on other sites

Are you asking: If I do a query and it tells me the current value is 'Option 3', then make the 'Option 3' option of the select box the default selected option?

 

You can use javascript to set the default selected option:

 

http://www.w3schools.com/jsref/prop_select_selectedindex.asp

 

And then pass it a variable containing which option ID it should select.

Link to comment
Share on other sites

Not Javascript; AVOID at all costs, not very user friendly if the browser doesn't support it!!

 

Right to have the selected value, extrapolate from this excerpt:-


<select name="SomeName" value="<?php echo ((isset($_POST['somename']) && !empty($_POST['SomeName'])) ? $_POST['SomeName'] : '');?>">
<option value="option1">First</option>
<option value="option2">Second</option>
<option value="option3">Third</option>
<option value="option4">Fourth</option>
</select>

 

Something along that line anyway, if its set (in the $_POST array) echo it's value in the text area! Typed OTF so more than likely contains errors but hopefully you get the jist... Simple when you think about it, unless I have misunderstood you in which case, ignore everything I just typed ;-p It's late at night here..

 

Rw

Link to comment
Share on other sites

I've got a HTML drop down box as similar to this:

 

<select name="dropdown">

<option>Option 1</option>

<option>Option 2</option>

<option>Option 3</option>

</select>

 

If I run a mysql query and get a result of "Option 3", is there anyway using PHP to give Option 3 the selected value?

 

Give us the context of what you are trying to do and I think we can give you better help unless taquitosensei's answer is what you needed.

 

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.