0

Hey everyone i have a database for a plumbing site i am working on.

They would like some way for customers to send in a ticket to there system and they need it up right now. I am building a ticketing system for them right now but i need a form that would work just for the time being.

Here is what i am trying to do.

I will have a drop down box (only what i am using right now. If there is a easier way let me know via check boxes or radio buttons) that will have items in there that corrispond with the database.
example: Kitchen, Bathroom, Laundry, ..... and so on.

What i need to do is be able to put the selected item into a mysql command so the next drop down box will display the items for what was selected from above.

So if Kitchen was selected it would show:
Dishwasher
sink
fridge
fridge - Front
fridge - Back

That is something that i would need it to be.

If anyone has any ideas please let me know and this way i can get this done.

I have only been using php for a while and have not found anything like this before so i am still learning.

Also if you know of any good reference points that i can beef up on my php i would appreciate the help.

Edited by ericjw316

5
Contributors
6
Replies
11
Views
4 Years
Discussion Span
Last Post by dcdruck
0

Check the Javascript forum. There are several threads on the subject. It is not possible using PHP only, AJAX is required.

0

You can see also here
http://www.daniweb.com/web-development/php/threads/430854/dropdown-search-from-mysql-database-help#post1847583

The answer I gave there is working but it was an answer for anyone that don’t like to be acquaintance with MVC and OOP. The IndexedList pattern described in PWF is solving most graphs and self referential issues (not only in AJAX needs) and I really can’t understand why major frameworks (not only in PHP) haven’t uncompressed that yet. The good thing is that when you understand how the mechanism works you can adjust it in any framework from Struts to CodeIgniter.

0

Can I convince you to repost it as a code snippet, just the functional code as it is. Would be great to have working code sample to point people to (preferably in the Web Development forum as it encompasses more than just PHP or Javascript).

0

While the methods proposed above are the best ways to handle this, there is another way to do this which involves mostly PHP and only a single line of Javascript. The caveat is that it causes a page refresh whenever the category dropdown is changed in order to get a new set of options for the second dropdown.

Basically, what you would do is the first time the page is loaded, just show the category dropdown with the options of Kitchen, Bathroom, etc. With Javascript, add an onchange event to that dropdown that will submit the form anytime the selected option is changed. So the user chooses a category from that list and the page refreshes. While the page is reloading, you are back in PHP land and you can detect which category they submitted and use that to grab an accurate list of items within that category (e.g. sink, toilet, fridge, dishwasher, etc.) and create the second dropdown containing the items in that list. If the user changes the category, the page will again reload with a new list of items to choose from.

I can post some example code if you want, but because this isn't the best way to do this (it may be the easiest though) I'll only post it if someone wants to see what the code would look like.

Dave

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.