Cornhusker40 Posted March 4, 2012 Share Posted March 4, 2012 Hi, I'm a php newbie, with some mysql experience. I have a mysql database as follows: Database=watch, Table=events - fields id, reportno, sdate, comments What I need is: 1. A dropdown list to display reportno from mysql database. 2. Depending on which reportno I choose, I'd like to open a popup(or separate) page to display the stored information. Tks in advance for any help Quote Link to comment https://forums.phpfreaks.com/topic/258261-dropdown-list-from-mysql-with-re-direction-on-select-option/ Share on other sites More sharing options...
Drummin Posted March 4, 2012 Share Posted March 4, 2012 No need to go to a different page. Just query DB based on POSTED record id from a selection form and display record below selection area. You can use a submit button or an onchange event to submit form. A popup or redirect can be done if you really want that as well. Start by making the selection form and then a few tests to query DB table based on selected value. Should be simple enough, just do it a step at a time with little tests. Quote Link to comment https://forums.phpfreaks.com/topic/258261-dropdown-list-from-mysql-with-re-direction-on-select-option/#findComment-1323842 Share on other sites More sharing options...
Cornhusker40 Posted March 4, 2012 Author Share Posted March 4, 2012 Tks for the info. I'll piddle about with the onChange. Quote Link to comment https://forums.phpfreaks.com/topic/258261-dropdown-list-from-mysql-with-re-direction-on-select-option/#findComment-1323887 Share on other sites More sharing options...
Cornhusker40 Posted March 4, 2012 Author Share Posted March 4, 2012 I'm lost!! Here us the code I'm using to gather the data, where do I add the onChange please? tks -----<?php mysql_connect("localhost", "username", "password") or die(mysql_error()); mysql_select_db("DARABASE") or die(mysql_error()); $query="SELECT reportno FROM TABLE"; /* You can add order by clause to the sql statement if the names are to be displayed in alphabetical order */ $result = mysql_query ($query); echo "<select reportno=event value=''>Report No.</option>"; // printing the list box select command while($nt=mysql_fetch_array($result)){//Array or records stored in $nt echo "<option value=$nt[id]>$nt[reportno]</option>"; /* Option values are added by looping through the array */ } echo "</select>";// Closing of list box ?> ----- Quote Link to comment https://forums.phpfreaks.com/topic/258261-dropdown-list-from-mysql-with-re-direction-on-select-option/#findComment-1323888 Share on other sites More sharing options...
Drummin Posted March 5, 2012 Share Posted March 5, 2012 See how this works for you. <?php mysql_connect("localhost", "username", "password") or die(mysql_error()); mysql_select_db("DARABASE") or die(mysql_error()); $query="SELECT reportno FROM TABLE"; echo '<form id="selectform" action="" method="post">'; $result = mysql_query ($query); echo "<select reportno=\"event\" onchange=\"this.form.submit()\">"; echo "<option value=\"\">-Select-</option>"; while($nt=mysql_fetch_array($result)){ echo "<option value=\"{$nt['reportno']}\">{$nt['reportno']}</option>"; } echo "</select>";// Closing of list box echo "</form>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/258261-dropdown-list-from-mysql-with-re-direction-on-select-option/#findComment-1323927 Share on other sites More sharing options...
Drummin Posted March 5, 2012 Share Posted March 5, 2012 Ahh, bad selection name in last post. echo "<select name=\"reportno\" onchange=\"this.form.submit()\">"; Quote Link to comment https://forums.phpfreaks.com/topic/258261-dropdown-list-from-mysql-with-re-direction-on-select-option/#findComment-1323948 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.