PHP MySQL Multiple Column Dynamic Dropdown

Greetings all,

I am currently in the process of setting up a e-commerce suite on a client
website but as I am a PHP MySQL newbie, I have come accross a few problems. I have a product page which has static information on it. I have a form with
a dropdown box. I want this dropdown box to show data from three different columns in a MySQL database table. These would be, Colour, Size and Price.
I have the database setup and running with Apache, PHP and MySQL all
installed, configured and fully operational.

I am using Dreamweaver MX 2004 and have already setup the dropdown on the
page using the DW insert List/Menu feature. I have been able to select what
dynamic data I would like to show by use of a recordset I have already setup
with all the relevant columns.

The first problem I have is the DW insert list/menu feature only allows me to show one column of data. I want to show all three one after the other in
the same dropdown box. I am sure this is possible because I have done this
using SQL in MS Access. I am unsure how this is done in PHP MySQL.

The second problem I have is that I would like the selected data from the
dropdown to be transported to the next page which will be the Review Cart
page. I have read on forums that the use of variables would do this for me
but am unsure as to how I would implement them into dropdown on the product page.

The third problem I have is I do not quite understand how the dropdown would only show the Colour, Size and Price options for the product of that product page. I have a dynamic dropdown tutorial which states that a parents and child lists would be needed, but seeing as I am only having one dropdown box, I think the child list would not be necessary.

Would I need to put a parentID column in the database table and give an ID for each set of options? for example, Bracelet would have Silver, Gold and Silver Plate.

Would I need to put an ID of 1 for each of these and then go on to put 2 for the next set of options for another product and 3 for the next and so on?

Any help would be much appreciated.

Thank-you all,

Regards,

Rue


print buildSelectList('colour',$array,'red'){



function buildSelectList($listName,$array,$selectedValue){

$list = '<select name="' . $listName . '">'. "n";

	while(list($key, $value) = each($array)){
		if($key == $selectedValue){
			$list .= '<option selected value="' . $key . '">' . 
					$value . '</option>'. "n";
		} else {
			$list .= '<option value="' . $key . '">' . 
					$value . '</option>'. "n";
		} 
	} 
	
	
	$list .= '</select>'. "n";
	
	return $list;
} 

Now the commentary:
$listName - you set it when you call the function
$array - //this is called from the database as a key/value pair
e.g
$array = 1 => red
2 => blue…etc
$selectedValue - you set it when you call the function

This function can now be called at any place to give you a drop down list using any array. Like states:
pass it an array of
AR => Arkansas
AZ => Arizona
etc

and it will give you the select list with the full name visible and the abbreviation as the value.

Hope this helps in some way.
Jeff

[/code]

Didn’t I answer this in the General section? Do not double post it irritates us and we tend to not answer then. Honest we will see you the first time.

ok sorry, i wasn’t sure if i would get a response from any of them so thought i could get a better chance by shotgunning.

Sorry, thanks for the help though.

Im slowly understanding this.

:)
Sponsor our Newsletter | Privacy Policy | Terms of Service