/    Sign up×
Community /Pin to ProfileBookmark

I have a combo box :

[CODE]<select name=”stock” id=”stock”>
<option value=”In Stock”>In Stock</option>
<option value=”Not in Stock”>Not in Stock</option>
<option value=”Discontinued”>Discontinued</option>
</select>
[/CODE]

I am connecting to the database and i want to display the results in a form and change the value of the combo box to the one value in the database for that record.

How would i set the combo box to the correct value using php.
Im not sure if this is a html or a php question

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@agent_x91Mar 10.2007 — You can simply echo the correct values into the appropriate place in the HTML once you've read the info from the database.

I'm not sure exactly what you're trying to do with that menu; do you want it to have it preselected with the correct option? You could use this:

[code=php]
<select name="stock" id="stock">
<?php
$info=1; /*example. Number representing the option number. Or you could just a string and check the string. Read into this variable from database*/

echo "<option value='In Stock'".((info==1)?" selected":"").">In Stock</option>";
echo "<option value='Not in Stock'".((info==2)?" selected":"").">Not in Stock</option>";
echo "<option value='Discontinued'".((info==3)?" selected":"").">Discontinued</option>";
?>
</select>
[/code]
×

Success!

Help @bunny1 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.15,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...