duanhuhong5255 2014-11-22 18:19
浏览 74
已采纳

PHP多个隐藏值选择选项

Is it possible to assign multiple values to select option drop down lists? I need to retrieve multiple pieces of data from each drop down when they are selected and I have only been able to get the "name" and an "id". The name is displayed for the user to select however it is the ID that is passed to be processed. Here is my code:

<?php
$att_1 = $att_1;
mysql_connect("xx.xx.xx.xx","xxxxxx","xxxxxx");
mysql_select_db("dezanjow_cf");
$sql=mysql_query("select id, name from model");
if(mysql_num_rows($sql)){
$select= '<select name="model">';
$select.='<option value="default">Select Model</option>';
while($rs=mysql_fetch_array($sql)){
     $select.='<option value="'.$rs['id'].'">'.$rs['name'].'</option>';
  }
}
$select.='</select>';
echo $select;
?>

This produces html that looks like:

<select name="model">
<option value="default">Select Model</option>
<option value="5">GH20</option>
<option value="6">GH21</option>
<option value="7">GH22</option>
</select>

I wish to display them like this (as example):

<select name="model">
<option value="default">Select Model</option>
<option value="5","abc">GH20</option>
<option value="6","def">GH21</option>
<option value="7","ghi">GH22</option>
</select>

Thus when the data is passed onto the next php script, I can use both data "5" and "abc" when the user selects "GH20". I have not seen much on Google about this and don't even know if this is possible. Please let me know if I am asking for the impossible! Many Thanks, Nick

  • 写回答

2条回答 默认 最新

  • douyinliu8813 2014-11-22 18:32
    关注

    Hey you cannot have multiple values like that because post or get will return just first value which in this case is 5

    <option value="5","abc">GH20</option>
    

    but you can make your value looks like this

    <option value="5,abc">GH20</option>

    and then in php script you can separate values by using explode function

    explode(',', $_POST['model']) which will return array that you can use array( 0=> 5, 1=>abc)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路