php - How can save drop down selected values. dropdown located in table column as shown in the image

949

I want to save each row by getting the ID of selected value in the dropdown like this:

Like This

954

Answer

Solution:

This is supposed to be a comment, but i have a low reputation here Hi Khan i do not really understand what you mean. A dropdown is basically a select option. The attribute "value" is what gets posted as the selected value. To save the value, simply have this:

$selected_value = mysqli_real_escape_string($connection, $_POST['name_of_dropdown_from_html_form']);

To get the value on an update form, do this:

<select id="id_of_field" name="name_of_field" class="form-control">
    <?php
    #i assume your select dropdown list is from a database. 
    #SO in that table, we have two columns, id_of_table and list_type. 
    #For example a list of different types of cars,
    #id(1) and list_type(BMW).
    #SO now we check if the id of the car is in the current dropdown list
    $list = $class->get_list();

    foreach ($list as $key => $value) {
        if ($value['id_of_table'] == $value['list_type']) {
            $selected = "selected='selected'";
            echo "<option value=\"{$value['id_of_table']}\" {$selected}>{$value['list_type']}</option>";
        } else {
            echo "<option value=\"{$value['id_of_table']}\">{$value['list_type']}</option>";
        }
    }
    ?>
</select>

try and integrate this with your project and let me know what you get

People are also looking for solutions to the problem: php - Parsing digit which has three letters with preg_match

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.