I have the following code:


$query = "SELECT Category FROM books";
$result = mysqli_query ($mysqli, $query);

echo '<select name="dropdown" value=""><option value="">Dropdown</option>';
    while($row = mysqli_fetch_array($result))
        echo '<option value="' . $row['Category'] . '">' . $row['Category'] . '</option>';
    echo "</select>";


the values of the drop down box are filled from the database. I was wondering if theres a way to have a select statement that will run when a user clicks on one of the options in the drop down menu and then populate the results in a table?

Im not really sure how to do it

Anyone able to help?


Edited by spud91

2 Years
Discussion Span
Last Post by hericles

With PHP that is generally done server side. For example, your user would select an option and then submit the form by hitting a button. The server side PHP gets the value of the option out of the $_POST data and then does what it needs to do, query a database, do a calculation, etc.
That requires a round trip as the formhas to be submitted but you can streamline the process by using AJAX to send of the value of the option the minute it is selected. The result will get posted back and the page can be updated.
You should find plenty of tutorials on the net if you look for 'php ajax'.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.