SteveNI Posted October 28, 2013 Report Posted October 28, 2013 I hope someone can offer me some guidance I am looking to populate a dropdown box with values from a database column Then when the user selects one of the dropdown options it then runs a second query that will produce a results table. I have my code to populate the dropdown <?php include ('connect-To-db.php'); $query = $mysqli->query("Select distinct`catagory` FROM `transactions` WHERE `Debit`!=0"); echo"<select name = 'catagory'>"; while ($row = $query->fetch_object()){ echo "<option value= '".$row->catagory."'>".$row->catagory."</option>"; } echo "</select>"; ?> And I also have my code that will query the database to produce the results I need <?php include ('connect-To-db.php'); if($query = $mysqli->query("Select `ThirdParty`,`Debit`,`Date` FROM `transactions` WHERE `Catagory` = 'shopping'")){ if($query->num_rows>0){ echo"<table border ='1' cellpadding='10'>"; echo "<tr><th>Payee</th><th>Amount</th><th>Date</th></tr>"; while($row=$query->fetch_object()){ echo "<tr>"; echo "<td>".$row->ThirdParty."</td>"; echo "<td>".$row->Debit."</td>"; echo "<td>".$row->Date."</td>"; echo "</tr>"; } echo "</table>"; } else{ echo 'No results to return'; } } else{ echo 'ERROR'.$mysqli->error; } ?>[code] What I dont quite understand is what I need to do to get the two pieces of code to run together. Can anyone point me in the right direction? Quote
falkencreative Posted October 29, 2013 Report Posted October 29, 2013 Unless I'm misunderstanding you... I'd think you would want to split it into two pages: -- On the first page, you'd have your generated dropdown menu within a form. The user would then select from the dropdown menu, and press the submit button, which would redirect them to a new page using the form's "action" value -- On the second page, you'd retrieve the value from the dropdown by using $_POST, and display the results to the user. Hope that helps get you started? Quote
SteveNI Posted October 29, 2013 Author Report Posted October 29, 2013 Unless I'm misunderstanding you... I'd think you would want to split it into two pages: -- On the first page, you'd have your generated dropdown menu within a form. The user would then select from the dropdown menu, and press the submit button, which would redirect them to a new page using the form's "action" value -- On the second page, you'd retrieve the value from the dropdown by using $_POST, and display the results to the user. Hope that helps get you started? Thanks Ben I was hoping to refrain from making the user press a submit button, I was hoping that they could could simply select an option in the dropdown menu and this would in turn would run the necessary query to produce a table. I am reading things about ajax and javascript onClick but to be honest I dont really understand what needs to be done. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.