donglu5728 2013-07-11 14:36
浏览 42
已采纳

Php选择基于动态下拉列表的默认下拉列表

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

  • 写回答

1条回答 默认 最新

  • douza6300 2013-07-11 14:43
    关注

    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>";
    }
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?