Forum Moderators: coopster

Message Too Old, No Replies

Drop Down List Based DB query

         

phparion

2:14 pm on Jan 10, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hi
I have a website in which I have like 20 Items. Every Item has its own distinguised Attributes. e.g

Item A
- Black
- Solid

Item B
- Socks
- Clothes

.. etc

In Database I have Two Tables. One for Items and One for Attributes. The ItemID from Items table is present in Attribute Table to link to attributes with a distinguished Item.

On the basis of above, I want to make two DropDows one for Items and One for Attributes, if someone select Item A from the Items Drop Down then Automcatically ONLY the Attributes related to Item A should Appear in the Attribute Dropdown.

how can i do this?
please give me your ideas on this. thanks

stu_uk

2:46 pm on Jan 10, 2006 (gmt 0)

10+ Year Member



if you want it to update automatically then you cannot use php, you need a client side script to do something like that.

The only way to do it in php is to use a form submit action obiviously this requires the whole page to be refreshed.

coopster

2:56 pm on Jan 10, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, stu_uk.

stu_uk is right, to handle this in PHP a round-trip request must be made to the server once a selection has been made from the first list box.

To do this client side would mean creating a JavaScript function(s) that would populate list 2 with only those valid items based on what was selected from list 1. A common task but only plausible when the lists are few and small.

phparion

3:38 pm on Jan 10, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



But the problem is that information about the Items and Attributes resides in Database, how can i use JS to fetch data from DB for this?

also please post some code so that i will get idea from it coz i am completely stuck with this.

thanks in advance