lundi 15 novembre 2021

Define HTML check boxes from database values

I have project with HTML PHP and SQL database. I designed HTML input form to collect data from user and put drop down menu using PHP. It collected data from SQL database using query and those data used to drop down list and user can select those data. I have using following codes in PHP section.

$quary2 = "SELECT Name FROM class ORDER BY Name";   
$results2 = mysqli_query($connection,$quary2);

while($result = mysqli_fetch_array($results2))
    {
    $Classes .= "<option value=\"{$result['Name']}\">{$result['Name']}</option>";
    }

In my data base there are several classes as Class_A, Class_B, Class_C and etc. (Admin can create new class or delete available class. Then when user select classes, showing classes can be different according to Admin's settings.)

In HTML form section I used following code to display Class names.

<p>
    <label for=" ">Classes Are</label><br>
    <select name="Classes[]" size="3" multiple >
    <?php echo $Classes ?>
    </select>
</p>

I tried to use this process through Check boxes (replace Drop down list from Check boxes) But I cant fix that. So, If someone can give proper way to do this it is highly appreciate.




Aucun commentaire:

Enregistrer un commentaire