【问题标题】:select & print multiple value from dropdown list从下拉列表中选择并打印多个值
【发布时间】:2010-04-11 18:41:57
【问题描述】:

在这段代码中,如何从下拉列表中选择多个值

<?php 


include ("connect.php");

$member_id = intval($_POST['sector_list']); 


if($member_id == 0) { 
    // Default choice was selected 
} 
else { 
    $res = mysql_query("SELECT * FROM members WHERE MemberID = $member_id LIMIT 1"); 
    if(mysql_num_rows($res) == 0) { 
        // Not a valid member 
    } 
    else { 
        // The member is in the database 
    } 
} 
?> 

<form method="post" action=""> 
    <input type="hidden" name="sector" value="sector_list">  
    <select name="sector_list" class="inputstandard" multiple="multiple">  
        <option value="0">send to</option> 
        <?php  
        $result = mysql_query('SELECT * from members') or die(mysql_error());   

        while ($row = mysql_fetch_assoc($result)) { 
            echo '<option value="' . $row['MemberID'] . '">' . $row['MemberName']. '</option>';  
        } 
        ?>  
    </select> 
</form> 

假设下拉列表包含 on (a,s,d,f,g,h,j,)

用户选择多个值 (a,s,j)

输出 = a,s,j 不仅是 j

???

【问题讨论】:

    标签: php list drop-down-menu


    【解决方案1】:

    (PHP Manual explanation)

    将列表的名称更改为数组(末尾有 []):

    <select name="sector_list[]" class="inputstandard" multiple="multiple">
    

    $_POST['sector_list'] 将是所有选定选项的数组

    【讨论】:

      【解决方案2】:

      将选择的名称更改为:

      <select name="sector_list[]" class="inputstandard" multiple="multiple">  
      

      在您的代码中,您可以像这样获得它们:

      print_r($_POST['sector_list']);
      

      【讨论】:

        猜你喜欢
        • 2018-12-16
        • 1970-01-01
        • 2023-03-21
        • 1970-01-01
        • 2021-12-14
        • 2016-07-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多