Steve_NI Posted October 26, 2013 Share Posted October 26, 2013 Hi I'm looking for some help. I am looking to query a mysql database and get distinct elements from a particular column and have the result set populate a dropdown box. After that I am looking for the ability of a user to click on one of those drop down options and from that it will produce all rows in the table that have that element in it. I'm new to php but the site I am developing is using PHP. First thing I need to know is that if this is even possible to do and if so would anyone have any tutorials that would guide me? thanks! Quote Link to comment Share on other sites More sharing options...
Steve_NI Posted October 26, 2013 Author Share Posted October 26, 2013 Ok I have managed to code it so that I can loop through the database and it has given me my drop down box populated with unique references from the database. Here is the code: $server = 'localhost'; $user='root'; $pass=''; $db = 'finance_checker'; $mysqli = mysqli_connect($server, $user, $pass, $db); $query = $mysqli->query("SELECT distinct `catagory` FROM `transactions`"); while($array[]= $query->fetch_object()); array_pop($array); ?> <h3>Payments Made by Catagory</h3> <select name="the_name"> <?php foreach ($array as $option): ?> <option value="<?php echo $option->Transaction; ?>"><?php echo $option -> catagory;?></option> <?php endforeach; ?> </select> <?php $query-> close(); ?> This now gives me a dropdown that looks something like: Food Clothes Entertainment Petrol Now what I would like is for my user to be able to click on one of these dropdown options lets say food and this then will link to a search which will for example "Select `payee`, `amount`, `date` From `transactions` Where `catagory` = Food" and then produce a new table of information of all food transactions ie: Payee Amount Date Tesco 20.45 26/10/2013 Boots 12.32 25/10/2013 How would I go about linking the dropdown options back to the database? Quote Link to comment Share on other sites More sharing options...
Barand Posted October 26, 2013 Share Posted October 26, 2013 Your dropdown needs to part of an HTML form. See http://php.net/manual/en/tutorial.forms.php Quote Link to comment Share on other sites More sharing options...
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.