Link to home
Start Free TrialLog in
Avatar of ucohockey
ucohockey

asked on

How to show a selected option in a dropdowm from mysql

I have a select dropdown that is populated from a mysql table which is working great. The dropdown is on a update profile page so how do I populate the dropdown from one table but then also get the value that was stored in a different table and show it as selected in the dropdown.

Here is the code for the dropdown.
<select name="type" id="type" data-placeholder="type" class="form-control form-control-select2 select2-hidden-accessible" data-fouc="" tabindex="-1" aria-hidden="true" required>
													<option value="" selected>Type</option>
													<?php
													$type = $link->query( "SELECT * FROM type" );
													while ( $rows = $vertical->fetch_assoc() ) {
														$type = $rows[ 'type' ];
														echo "<option value ='$type'>$type</option>";
													}
													?>
												</select>

Open in new window

Avatar of Robert Granlund
Robert Granlund
Flag of United States of America image

You will need to write a concatenated query.
"SELECT type.type, other_value.other_value
FROM type, other_table
WHERE id.type = id.other_table"

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial