olaoyesunday Posted August 20, 2020 Share Posted August 20, 2020 Please, I want to convert this single select option to multiple choice select options. i,e to select more than one option in the select dropdown <?php $get_sizes = "select * from sizes"; $run_sizes = mysqli_query($con,$get_sizes); while ($row_sizes=mysqli_fetch_array($run_sizes)){ $size_id = $row_sizes['size_id']; $size_name = $row_sizes['size']; echo " <option value='$size_id'> $size_name </option> "; } ?> </select><!-- form-control Finish --> Link to comment Share on other sites More sharing options...
Larry Posted August 21, 2020 Share Posted August 21, 2020 Add the "multiple" property to the opening select tag: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select Link to comment Share on other sites More sharing options...
olaoyesunday Posted August 21, 2020 Author Share Posted August 21, 2020 Thanks very much sir, I still need your help. How do I allow size_id column in product table to store more than one size_id on a single record? I tried it directly in phpmyadmin to insert more than one size_id on the size_id column but it was given error Link to comment Share on other sites More sharing options...
Larry Posted August 22, 2020 Share Posted August 22, 2020 Ah, no, you can't do that. You'll need to use PHP to break the multiple selections into their single counterparts and insert each one separately. 1 Link to comment Share on other sites More sharing options...
olaoyesunday Posted August 23, 2020 Author Share Posted August 23, 2020 okay thanks but I am trying to use foreach loop where I want to enter the $_Post['size'] into database but don't know how to assign the $i variable below back to the $size variable if(isset($_POST[‘submit’])){ $size = $_POST[‘size’]; foreach ($size as $i) { echo ("$i<br>"); } $insert_product = "insert into products (size) values (’$size’) Link to comment Share on other sites More sharing options...
Larry Posted August 24, 2020 Share Posted August 24, 2020 You need to execute the query from within the FOREACH as that's the only place you have access to each individual selected size. Link to comment Share on other sites More sharing options...
Recommended Posts