doulangyu9636 2016-04-25 07:19
浏览 36
已采纳

选择下拉列表中选择的名称

Query for select God from God table

$sth =$dbh->prepare("SELECT god_id,god_name_ml,god_name_en,image,info_ml,info_en,details_ml,
       details_en,rounds_ml,rounds_en,mantra_ml,mantra_en,display_order FROM god");
       $sth->execute();

Query for select deity from deity table.Here god_id is the foreign key from god table

   $stmt = $dbh->prepare("SELECT deity_id,god_id,deity_name_ml,deity_name_en,info_ml,info_en,details_ml,
      details_en,mantra_ml,mantra_en,display_order FROM deity
      WHERE deity_id = :deity_id");
    $stmt->bindValue(':deity_id',$deity_id,PDO::PARAM_INT);
    $stmt->execute();
    $result = $stmt->fetchAll();
    $temp_array=$result[0];
    $god_id=$temp_array['god_id'];

display code for displaying god in dropdown from god table

<?php while ($row = $sth->fetch(PDO::FETCH_ASSOC)) { ?>
       <option value="<?php echo $row['god_id'];?>">
         <?php echo $row['god_name_en']; ?>
       </option>
       <?php } ?>
       </option>
   </select>

what I need is, in dropdown list the given god_id in god table is present in deity table make it as selected. only I need is selected Id's are selected

  • 写回答

3条回答 默认 最新

  • drnycqxwz63508434 2016-04-25 07:33
    关注

    Just check both the id's are same or not, try this :

    <?php while ($row = $sth->fetch(PDO::FETCH_ASSOC)) { ?>
      <option <?php if($row['god_id'] == $god_id) { echo "selected='selected'"; } ?> value="<?php echo $row['god_id'];?>"><?php echo $row['god_name_en']; ?></option>
    <?php } ?>
    </option>
    </select>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)