Jump to content

Recommended Posts

Quote

I have this code here. i wanted to know how i can be able to make multiple selections from the returned data from the database and how to save them

Quote

 



 <select name="troom"  multiple class="form-control" required>
                                    <option  selected="true" disabled="disabled">--Select a room--</option>
                                    


                                        
                                        $records =mysqli_query($con, "select * from room where TRoom not in (select TRoom from roombook where cin <= '$checkout' and cout >= '$checkin');");
                                        
                                        while ($data = mysqli_fetch_array($records)) {
                                            echo "<option value='" . $data['TRoom'] . "'>" . $data['TRoom'] . "</option>"; //displaying data in option menu
                                        }
                                    }

                                    ?>

                                </select>

 

 

Link to comment
https://forums.phpfreaks.com/topic/312075-multiple-selection-in-an-option-list/
Share on other sites

Example...

<?php
    if ($_SERVER['REQUEST_METHOD']=='POST') {
        
        echo "<b>You selected</b><ul>";
        foreach ($_POST['fruit'] as $fruit) {
            echo "<li>$fruit</li>";
            // update database here
        }
        echo "</ul><hr>";
        
    }
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Example</title>
</head>
<body>
    <h1>Example</h1>
    <hr>
    <form method="POST">
    Fruit: 
    <br>
    <select name="fruit[]" multiple size="10">
       <option>Apple</option>
       <option>Banana</option>
       <option>Date</option>
       <option>Kiwi</option>
       <option>Lemon</option>
       <option>Melon</option>
       <option>Orange</option>
       <option>Pear</option>
       <option>Quince</option>
   </select> 
    <br>
    <input type="submit" name="btnSubmit" value="Submit">
    </form>
</body>
</html>

 

26 minutes ago, Barand said:

Example...


<?php
    if ($_SERVER['REQUEST_METHOD']=='POST') {
        
        echo "<b>You selected</b><ul>";
        foreach ($_POST['fruit'] as $fruit) {
            echo "<li>$fruit</li>";
            // update database here
        }
        echo "</ul><hr>";
        
    }
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Example</title>
</head>
<body>
    <h1>Example</h1>
    <hr>
    <form method="POST">
    Fruit: 
    <br>
    <select name="fruit[]" multiple size="10">
       <option>Apple</option>
       <option>Banana</option>
       <option>Date</option>
       <option>Kiwi</option>
       <option>Lemon</option>
       <option>Melon</option>
       <option>Orange</option>
       <option>Pear</option>
       <option>Quince</option>
   </select> 
    <br>
    <input type="submit" name="btnSubmit" value="Submit">
    </form>
</body>
</html>

 

my problem with this  is, the option list is populated from the database. Do you mind implementing the code you posted  in the quoted code?

<select name="troom"  multiple class="form-control" required>
                                    <option  selected="true" disabled="disabled">--Select a room--</option>
                                    


                                        
                                        $records =mysqli_query($con, "select * from room where TRoom not in (select TRoom from roombook where cin <= '$checkout' and cout >= '$checkin');");
                                        
                                        while ($data = mysqli_fetch_array($records)) {
                                            echo "<option value='" . $data['TRoom'] . "'>" . $data['TRoom'] . "</option>"; //displaying data in option menu
                                        }
                                    }

                                    ?>

                                </select>

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.