Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select multiple not working

Tags:

jquery

php

I have a select dropdown in html but it won't select multiple values. here is the code that I have for this:

<div class="col-sm-10">          
    <select multiple id="cmbService" name="cmbService" class="form-control" >
        <option value="0">- Select One -</option>
            <?php                                       
                try{
                    $dbHost = "localhost";
                    $dbUser = "mdchadmin";
                    $dbPass = "123456";
                    $dbName = "mdch_new";

                    $conn = new mysqli($dbHost, $dbUser, $dbPass, $dbName);
                    if ($conn->connect_error) {
                        die("Connection failed: " . $conn->connect_error);
                    } 
                    $sql = "SELECT PROMO_NUMBER, PROMO_NAME FROM PROMOS where status=1";
                    $result = $conn->query($sql);
                    if ($result->num_rows > 0) {
                        while($row = $result->fetch_assoc()) {
                            echo "<option value=\"{$row['PROMO_NUMBER']}\">{$row['PROMO_NAME']}</option>";
                        }
                    }                                       
                    $conn->close(); 
                }catch (Exception $e) {
                    echo 'Error: ' . $e->getMessage();
                }                                           
            ?>
    </select>
</div>

EDIT: IT NOW WORKS THANKS TO THE ANSWER. BUT NOW I HAVE A NEW PROBLEM(kinda) and i'm going thru this

so i did what u suggested, and im getting this $customer array in my other php file which results to:

te,GIAN MARCO.'_'.1235
g,g.'_'.123

where 1235 and 123 are  the  data on the mobile numbers column.
the problem is , when i do 

$mobile=(explode("_",$customers));
it doesn't give me anything when i output it via: 

foreach($mobile as $z) {
echo $z; echo "<br>";}

@identity unknown

like image 411
Gian Marco Te Avatar asked Jun 13 '15 14:06

Gian Marco Te


1 Answers

You simply need to add an square bracket in your name attribute name="cmbService[]"

 <select id="cmbService" name="cmbService[]" class="form-control multiple " >
like image 172
Abhinav Avatar answered Oct 13 '22 11:10

Abhinav