0

Building an edit users form for my system and having a little trouble trying to figure out how to do a selected="selected" for the value in the dropdown that goes with the users information in the database.

This is my code: http://pastebin.com/EVdUfTzN

The names of the offices are stored in one table called offices and the value of the office that the patient went to is stored in patients. Basically I want to select the information from both tables and add a selected option on it.

Here is picture of the offices table
enter image description here

Here is a picture of the patients table
enter image description here

Do you understand what i am trying to do? Maybe even simplify it so its one query with INNER JOIN

3
  • you want to be auto selected the one that is stored in db? Commented Jul 11, 2013 at 14:41
  • Yes exactly, Im having trouble where to do that. Commented Jul 11, 2013 at 14:41
  • $row['office_id'] is $row['pat_loc']? Commented Jul 11, 2013 at 14:43

1 Answer 1

1

Try this (replace lines 25-29):

<?php
while ($dd_loc_row = mysql_fetch_array($dd_loc_result)) {
    echo "<option value=\"" . $dd_loc_row['office_id'] . "\"".($row['pat_loc'] == $dd_loc_row['office_id'] ? ' selected="selected"' : '').">" . $dd_loc_row["office_name"] . "</option>";
}
?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.