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

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题