How do I assign a database query value in such a way that the value becomes the selected value in a drop down box.
jtreyes
0
Newbie Poster
Recommended Answers
Jump to PostHow do I assign a database query value in such a way that the value becomes the selected value in a drop down box.
I do not entirley understand the question, do you mean that you want to have some set variables, then one of them from a database, or …
Jump to PostOk so are you saying that you already have the values of the options in HTML, or are the values selected from the database??
Jump to PostOk for this example i have put the option building into the code from the database
<?php $conn=mysql_connect("localhost","root","") or die(mysql_error()); mysql_select_db("testbase") or die(mysql_error()); $result=mysql_query(" SELECT * FROM users"); $option=""; while($row=mysql_fetch_array($result)) { $option .= "<option"; if ($_POST['name']==$row['username']) {$option.= " selected='selected'";} $option .= ">" . $row['username'] . "</option>"; } …
All 9 Replies
hooray
1
Junior Poster in Training
jtreyes
0
Newbie Poster
hooray
1
Junior Poster in Training
jtreyes
0
Newbie Poster
hooray
1
Junior Poster in Training
jtreyes
0
Newbie Poster
hooray
1
Junior Poster in Training
qnstner
0
Newbie Poster
Murshid_2
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.