dor65412 2016-04-25 18:41
浏览 20
已采纳

PHP / MySQL:选择框中的值与关联数组中的值相关联

I have a dropdown list (HTML select box) which gets values from this MySQL query:

"SELECT cdID, cdTitle FROM CD ORDER BY cdID"

The result is then stored in an associative array, which is then output to the dropdown list:

<?php
echo '<select name= "list" id="list">';
while ($row = mysqli_fetch_assoc($result)){
echo '<option value="'.$row['cdTitle'].'">'.$row['cdTitle'].'</option>';
}
echo '</select>';
?>  

My issue is that I would like the user to see the title of the CD, but for the actual value to be "cdID" as that is the foreign key used in my database.

  • 写回答

2条回答 默认 最新

  • dsux90368 2016-04-25 18:48
    关注

    Just change the attribute echoed out for value -

    <?php
    echo '<select name= "list" id="list">';
    while ($row = mysqli_fetch_assoc($result)){
    echo '<option value="'.$row['cdID'].'">'.$row['cdTitle'].'</option>';
    }
    echo '</select>';
    ?>  
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 socket通信实现多人聊天室疑惑
  • ¥15 DEV-C++编译缺失
  • ¥33 找熟练码农写段Pyhthon程序
  • ¥100 怎么让数据库字段自动更新
  • ¥15 antv g6 力导向图布局
  • ¥15 quartz框架,No record found for selection of Trigger with key
  • ¥15 锅炉建模+优化算法,遗传算法优化锅炉燃烧模型,ls-svm会搞,后面的智能算法不会
  • ¥20 MATLAB多目标优化问题求解
  • ¥15 windows2003服务器按你VPN教程设置后,本地win10如何连接?
  • ¥15 求一阶微分方程的幂级数