Jump to content
Larry Ullman's Book Forums
Sign in to follow this  
olaoyesunday

Single select option to multiple choice select option

Recommended Posts

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 -->

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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. 

  • Like 1

Share this post


Link to post
Share on other sites

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’)

Share this post


Link to post
Share on other sites

You need to execute the query from within the FOREACH as that's the only place you have access to each individual selected size. 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...