Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
PHP MySQL Multiple Column Dynamic Dropdown
Old 08-18-2004, 08:20 AM PHP MySQL Multiple Column Dynamic Dropdown
Junior Talker

Posts: 2
Trades: 0
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
MadRueNRG(UK) is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-19-2004, 11:49 PM
ACJavascript's Avatar
Humble Mod

Posts: 548
Location: CT, USA
Trades: 0
Okay, Lets see if I can aswer all of your questions.

Your question regarding how you could display the products colors for that single product.

Create a color and size table. For the price I would put the price with the product information.

For every color have a productID. For Example you could do:
CREATE TABLE colors (
color_id MEDIUMINT(8) NOT NULL AUTO_INCREMENT,
color_text VARCHAR(85) NOT NULL,
product_id MEDIUMINT(8) NOT NULL DEFAULT '0',
PRIMARY KEY color_id(color_id)
);

Do the same with the size.

Now when pulling information from the database to display on the drop down you can do somthing like this.

Code:
<?php

//Id number - I am assuming its from a GET variable
$id=$_GET['id'];

//Do all of your mysql connections

//Do query
//s=size, c=color, p=product
$query_colors="SELECT c.product_id,c.color_text,c.color_id,p.product_id,p.product_name,p.product_description FROM products AS p LEFT JOIN color c ON c.product_id=p.product_id WHERE p.product_id='$id'";
$query_size="SELECT s.product_id,s.size_text,s.size_id,p.product_id,p.product_name,p.product_description FROM products AS p LEFT JOIN size s ON s.product_id=p.product_id WHERE p.product_id='$id'";

//Run query;
$result=@mysql_query($query_color);
$result2=@mysql_query($query_size);

//Lets create the select
?>
<select name="color_size">
<?php
//Lets loop through the colors (only if there are some)
if(mysql_num_rows($result)==0){
}else{
while($row=mysql_fetch_array($result)){
?>
<option value="<?php echo($row['size_id']); ?>"><?php echo($row['size_text']); ?>
<?php
}
}
//Lets loop through the sizes
if(mysql_num_rows($result2)==0){
}else{
while($row=mysql_fetch_array($result2)){
?>
<option value="<?php echo($row['color_id']); ?>"><?php echo($row['color_text']); ?>
<?php
}
}
?>
</select>
Now when the user adds this item to the cart you can pull the color_id and size_id and match it in the mysql database.

I hope this answers some of your questions. I apologize if I have missed your entention.
__________________

Please login or register to view this content. Registration is FREE
- 100 Satisfied Customers - Custom Programming and Web Development
ACJavascript is offline
Reply With Quote
View Public Profile Visit ACJavascript's homepage!
 
Old 08-20-2004, 01:30 PM
Junior Talker

Posts: 2
Trades: 0
ok erm, slightly confusing but i think i got the jist of it though.

I have decided to try 2 drop downs but i will try you suggestion as a backup.

Thanks,

Rue
MadRueNRG(UK) is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to PHP MySQL Multiple Column Dynamic Dropdown
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.78212 seconds with 12 queries