Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-27-2012, 03:10 PM   PM User | #1
367
New Coder

 
Join Date: Nov 2011
Posts: 11
Thanks: 3
Thanked 0 Times in 0 Posts
367 is an unknown quantity at this point
Dynamic dropdown list

Hi,

i need a two dropdown lists where first (manufacturer) populates second (models) and when submit button is clicked it should lead to page of model, like this: index.php?p=view&m=shop&id=<certain_id>

all data is in one table and i can't change that: id, manufacturer, model, price, description

is there any example of something like this or someone knows how to do that?

thank you
367 is offline   Reply With Quote
Old 12-27-2012, 04:20 PM   PM User | #2
TFlan
New Coder

 
Join Date: Dec 2012
Location: USA
Posts: 82
Thanks: 3
Thanked 17 Times in 17 Posts
TFlan is an unknown quantity at this point
You have a couple options:

1) Ajax

You can use Ajax to onChange(this.value) of the manufacturer select, query your database with "WHERE `manufacturer`= 'value.passed.to.js.function'". Then populating your second dropdown with the return results.

2) Preload every list.

This is the option I would use. If I'm a user on your site and I have to wait X seconds every time I want to see a new list of models, I'm not happy.

I would use PHP to query your database for (unfortunately) your entire table (unless you know you don't need a few rows) for the `id`, `manufacturer`, and `model` columns (unless you need more).

Using those results, I would print them out into a javascript array and use the onChange() function of the manufacturer select to call for the respective array, which would populate the model select.

Quote:
Originally Posted by 367
when submit button is clicked it should lead to page of model, like this: index.php?p=view&m=shop&id=<certain_id>
Code:
<form method="get" action="index.php?p=view&m=shop">
<select name="id">
<option value="mysql.id">mysql.model</option>
TFlan is offline   Reply With Quote
Old 12-27-2012, 04:25 PM   PM User | #3
Redcoder
Regular Coder

 
Redcoder's Avatar
 
Join Date: May 2012
Location: /dev/couch
Posts: 309
Thanks: 2
Thanked 46 Times in 45 Posts
Redcoder has a little shameless behaviour in the past
That can be easily done with Javascript. You need to use Client-Side Coding for that then use event triggers where selecting one option will trigger different values to be loaded on the other Drop-Down list.

Jquery can help you if you use the .change() trigger or .click()

http://api.jquery.com/change/

http://api.jquery.com/click/

Of course you need to know Jacascript to do that one.

If it is a particularly long Dropdown, you may combine it with Ajax and load it dynamically using a back-end PHP script that fetches Database data.
__________________
For professional Hosting and Web design.....


NetEssentials.co.uk
Redcoder is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:33 AM.


Advertisement
Log in to turn off these ads.