Jump to content

dyanamic combo box


mona

Recommended Posts

Iam new here and need your help please!Iam working with a php, mysql program, In this program I have let's say 3 combo box (select tags)one for student_id , one for first name and the other for last name,I already got data from mysql using( select * from student) and put them in these combos, but I need onchange of each one to execute another select statement (for example if we change first name select * from student where firstname=....), so I need to clear the other combos and refill them again according to the new query. so, I'll obtain all the students whose first name=...here we need to call a function that makes combo clear using javascript (form1.fn.options.length=0) and also execute a new query(select * from student where fn=..) and refill combos again(new option(....))my questions are:1. do I need to call php function or javascript function onchange of select tag and if php how can i do that?2.how can we take form variables (value of select) and put them in sql statement?if any have idea about this please help me because I am lost and I dont know what to do.

Link to comment
Share on other sites

If you're going to make a call to mysql every time the user changes something then use php. This means that the page will have to be reloaded every time.Your other option (if your database is very small) is to use php to load all your data into a javascript variable the first time the page is loaded. Then you won't need to reload the page every time 'cause you can use javascript to do all the work.To use the value of the select element just give the element a name (eg. <SELECT name="first_name" >) and then submit the form. You can then use "$_POST['first_name']" if you used the POST method or "$_GET['first_name']" if you used the GET method in your sql query. (eg. "SELECT * FROM students WHERE first_name = {$_POST['first_name']}")Hope this helps. :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...