-1

I have a dropdown that is loaded with dates(date_entered) pulled from a database. My table has the columns Size, Item, Description, Unit, Price, Usage, and Item Number.

My database has the same but also a date_entered. When the user selects a date from the dropdown, I need to fill the table with the corresponding data (size, item, etc.). However I'm not sure how to go about that since I think php only loads data when the page is requested. Below is the code for my dropdown. Would I add a display button for the user to click? Any help would be appreciated. Thank you

                    <label for="">Select invoice</label>
                    <div class="input-group">
                        <select name="invoice" id="invoice" class="form-control" type="text" list="id" placeholder="Select Number"value="<?php $Date_entered ?>">
                        <span class="input-group-btn">
                            <datalist name="id" id="id">&nbsp;<span class="caret"></span>
                            <?php
                            include("Connect.php");
                            $result=mysql_query("SELECT Date_entered FROM orders");
                            while ($row = mysql_fetch_array($result)) {
                                unset($id);
                                $id = $row['Date_entered'];
                                echo '<option value="'.$id.'">'.$id.'</option>';
                            }
                            ?>
                            </datalist>
                        </span>
                        </select>
                    </div>
John
  • 151
  • 3
  • 12
  • You can use ajax to load more data once user selects a date. Take a look at this - http://stackoverflow.com/questions/32389767/how-do-i-execute-a-php-query-on-select-option-choice-using-ajax – vabii May 15 '17 at 18:28

1 Answers1

0

You have to use AJAX for that. The best way is to define a function, which runs when user change the drop-down selector and in this function, insert the data into database and then make a ajax call to fetch dates. In AJAX call, on success callback function, re-populate your drop-down list. Look at this post for more help: How to populate dependable drop down using AJAX

Community
  • 1
  • 1
Abdullah Danyal
  • 1,106
  • 1
  • 9
  • 25