Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: PHP MySQL
Hi,
 
I want to create 2 select boxes. The option of the first box chosen will decide the options visible in the second select box. For example:
 
Select box A contains options 2010, 2011, 2012
 
Select box B contains movies names according their release year.
 
Now when say option 2012 is selected in box A, only those movies which have their release year on 2012 are displayed.
 
Please help coding in PHP/MySQL.
 

Thanks in advance.
Posted 17-Sep-12 5:37am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You need a simple query with a WHERE clause!
 
Example:
SELECT  
  movieNames
FROM
  Movies
WHERE
  movieYear = '2012'
You will have to pass movieYear as a parameter to query where its value will be equal to boxA option selected. Set query result as a datasource of this boxB.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hi Friend,
These tips may help you. I am sorry that I will not be providing you with codes since I have not one ready, and it really takes time to create one. But I will be giving you hints toward which you can move your way to reach the success.
 
1. First of all create a MySQL database and possibly create two tables, the one for the year and the another for film name or something like that, you are able to create one that seems more logical to you.
 
2. The second step is using AJAX (Yes, Javascripting) unless you have planned to reload the page everytime the user select an Year from the first select box.
 
3. The third step will be if you are going with creating an AJAX script. Create a function that will submit the Value of first selectbox on a onchange() event.
 
4. Create a page in php without any html inside it. This page will receive this data (the value of Selectbox1) and process it using MYSQL query to get a list of the array that will be storing the name of the Movies. Echo this data using this kind of code as example:
foreach($dataarray as $moviename)
{
 echo '<option>'.$moviename.'</option>';
}
 
5. In the ajax script, simply put this code in a block defined with ID name like this:
if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
 document.getElementById("movieid").innerHTML = xmlhttp.responseText;
}
and, in the html part define something like this:
<select>
<div id="movieid"><option>Wait...</option></div>
</select>
6. Now you have your very own professional looking Select Box System, in which the Items displayed in one box will depend on the item selected in another box.
 
Hope it has helped you. I will possibly post the code if I get time to write one very soon.
 
Regards
Tushar Srivastava
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 435
1 Maciej Los 335
2 OriginalGriff 278
3 CHill60 180
4 Sinisa Hajnal 180


Advertise | Privacy | Mobile
Web02 | 2.8.141022.2 | Last Updated 17 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100