hobbiton73 Posted August 4, 2011 Share Posted August 4, 2011 Hi, I wonder whether someone may be able to help me please. I'm very new to PHP so please bear with me. I have a three tables in MySQl database called 'userdetails' 'detectors' and 'detectorsearchheads' with the following fields: userdetails userid username detectors userid detectorid detectordescription detectorsearchheads userid detectorid detectorsearchheadid detectorsearchheaddescription What I would like to do, if at all possible, is to have the first drop down for detectors which is user specific (i.e pertinent to the current users records) and then another dropdown menu which is again user specific but will then will only show the values pertinent to the value of the first drop down menu. But I must admit I haven't a clue where to start. Would be at all posssible please that someone could give me a little bit of help to start me off with this. Many thanks and regards Quote Link to comment https://forums.phpfreaks.com/topic/243825-use-php-to-populate-html-form-drop-down-boxes-with-mysql-data/ Share on other sites More sharing options...
DeX Posted August 4, 2011 Share Posted August 4, 2011 I've coded this a few times but I'm not sure if there is a better way to do it. This is how I did it: Use PHP to pull all the values from the database and put them into 3 separate arrays, there are lots of tutorials around for this. Populate the first SELECT box with the proper values and attach an onchange function to it to call Javascript. Inside your Javascript, you'll grab the other SELECT box by its ID and inject the proper values into it. If I confused you, this might be a little too advanced for you. Quote Link to comment https://forums.phpfreaks.com/topic/243825-use-php-to-populate-html-form-drop-down-boxes-with-mysql-data/#findComment-1251950 Share on other sites More sharing options...
radiations3 Posted August 4, 2011 Share Posted August 4, 2011 you can easily do it if you are using dreamweaver it gives the option of listing values from the database. Quote Link to comment https://forums.phpfreaks.com/topic/243825-use-php-to-populate-html-form-drop-down-boxes-with-mysql-data/#findComment-1251953 Share on other sites More sharing options...
hobbiton73 Posted August 4, 2011 Author Share Posted August 4, 2011 Both, Many thanks for replying to my post. As I said I am fairly new to this, so I'm not too sure how I would go about implementing the first method proposed at the moment. I am however using Dreamweaver. I was aware that there was this functionality available, but I found the help files pretty poor. Could you perhaps please elaborate as to how I woudl go about doing this. Many thanks and regards Chris Quote Link to comment https://forums.phpfreaks.com/topic/243825-use-php-to-populate-html-form-drop-down-boxes-with-mysql-data/#findComment-1251954 Share on other sites More sharing options...
radiations3 Posted August 4, 2011 Share Posted August 4, 2011 Create a RECORDSET FOR THE PARTICULAR VALUE YOU NEED TO DISPLAY IN THE DROP DOWN MENU THEN SELECT THE DROP DOWN MENU AND SEE IN PROPERTIES THERE YOU'LL FIND THE OPTION OF DYNAMIC VALUES CLLICK ON IT THEN SET YOUR RECORDSET TO IT AND GET IT DONE ITS THAT SIMPLE... Quote Link to comment https://forums.phpfreaks.com/topic/243825-use-php-to-populate-html-form-drop-down-boxes-with-mysql-data/#findComment-1251958 Share on other sites More sharing options...
hobbiton73 Posted August 8, 2011 Author Share Posted August 8, 2011 Hi, I've been working on this over the last few days and I've finally got my first drop down menu to work. I'm now unsure about how to progress this by adding another drop down menu with the values shown dependent on the users choice in the first drop down menu. Here is the code I am using: <?php mysql_connect("hostname", "username", "password") or die("Connection Failed"); mysql_select_db("databasename")or die("Connection Failed"); $query = "SELECT * FROM detectors WHERE `userid` = '1' ORDER BY 'detectorname' ASC"; $result = mysql_query($query); ?> <select name="detectorname"> <?php while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { ?> <option value="<?php echo $line['detectorname'];?>"> <?php echo $line['detectorname'];?> </option> <?php } ?> </select> What I'd now like to be able to do is to only show those values in the second drop down menu from the table 'searchheads' where the 'detectorid' is the same as that chosen in the first drop down menu which is populated from the table 'detectors'. I just wondered whether it would be at all possible please that someone could show me how I would go about doing this. Many thanks and regards Chrid Quote Link to comment https://forums.phpfreaks.com/topic/243825-use-php-to-populate-html-form-drop-down-boxes-with-mysql-data/#findComment-1254264 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.