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

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效