Re: PHP- Dependant dropdown based on Mysql queries

From: Date: Mon, 30 Aug 2004 19:35:22 +0000
Subject: Re: PHP- Dependant dropdown based on Mysql queries
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-195191@lists.php.net to get a copy of this message
<Francisco Puente XFMP (QA/EMC)> wrote in message news:BD19652268335B4490925246D48B045002C8D7FE@lmc37.lmc.ericsson.se... > Hi All, > I'm trying to generate a PHP page with 3 or 4 dropdown menus, each of one dependant upon each other, that means: > #2 dropdown should change upon selecting something on dropdown #1, #3 should change based on the selection at #2 to finally submit the desired query. Each dropdown menu should be generated from a mysql query based on the previous selection. > I need to generate mysql queries based on each dropdown selection and the page should reload the content for the next dropdown menu. I couldn't yet figure out how to accomplish this. > Let me know if I make myself clear enough :) > Any help is very welcome!! > > Thanks in advance, > > Francisco Hi Francisco, just point the form action to $_SERVER['PHP_SELF']. Then check the POST value of the relevant dropdown and do your queries. For example: // the value of your selects will probably be ids that's why you should cast them to integers if (isset($_POST['select1'])) { $select1 = (int) $_POST['select1']; // do your query for select2 } if (isset($_POST['select2'])) { $select2 = (int) $_POST['select2']; // do your query for select3 } if (isset($_POST['select3'])) { $select3 = (int) $_POST['select3']; // do your query for select3 } if (isset($_POST['select4'])) { $select4 = (int) $_POST['select4']; // insert your data } I hope you get my point. For user convenience you could use JavaScript's onChange() event to auto-submit the first three selects when the user has selected a value. Best regards, Torsten Roehr

« previous php.general (#195191) next »