close ad
Help us test the new Databridge BETA with MySQLi support
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

SQL for Options

Thread began 11/11/2009 3:54 pm by steven348539 | Last modified 11/18/2009 2:55 pm by CraigR | 3020 views | 10 replies |

steven348539

SQL for Options

I am not understanding how to do this from the recipe pdf file.

I am selling prints online and different prints have different sizes available. I have setup a table 'Sizes' that has:

SizeCatId to group a set of sizes for a print (1 = 8x10, 2= 8x10 & 16x20, etc.)
SizeDesc to give the text for the dropdown box to select which size.
SizePrice to give the price for that size print.

Within the items table I have a column called ItemSizes.

How would I write the SQL commands for the items and details pages so that based on the number in the ItemSizes column the rows from the sizes table will be returned to fill the dropdown box? (And if there is any trick to have this add the correct price to the cart when the add button is pressed)

Thanks

Sign in to reply to this post

Eric Mittman

The specific SQL that you will need will depend on some more details about your structure. You have a sizes table that has a cat id, but how does this cat id relate to the items sizeID? Does the sizeID column in your items table directly correspond to the SizeCatID column of the sizes table?

Also, does this mean that you have multiple items that are the same but have different SizeID's? An example of the all the columns in the tables involved would help to clear this up.

For your details page you should have a recordset that joins the items and sizes tables, and filters on the id for the selected item. How this is formed though will depend on the details mentioned above.

Sign in to reply to this post

steven348539

Attached should be screen shots of the items and sizes tables.

I would like any rows from the Sizes table to be returned where the Sizes.SizeCatID = Items.ItemSizes

Multiple items could use the same ItemSizes as print sizes are quite standard.

My thinking is (and feel free to correct it if there is a better way) when the item was pulled from the db, the ItemSizes could be used to pull the data from the sizes table to populate a dropdown that lists the size and price and the selected value would equal the SizeID (key), which could then be used to bind the size and price for the cart, or it could be bound to the card and then pull the information out of the db again for that SizeID (not sure which is the best way here)

By making a column that would correspond to a group of sizes a picture could be printed as would save me from making multiple items of the same picture, but available as different sizes. It would make viewing the available prints cumbersome if someone needed to look at 2-4 images of the same picture just for the different sizes.

Sign in to reply to this post

Eric Mittman

Thanks for the screen shots of the table structure, this is very helpful. I'm still a little confused though about how these tables relate to one another.

If you have a unique item per item id, an each item id has a single size id how do you associate multiple sizes with a single item?

Usually in this scenario you would have a relational or joining table. This table would hold item id's and corresponding size ids. So in this table you could have the same item listed multiple times but the sizes entry will be different for each item entry.

This is the part that I'm not making a connection with. If the item table holds a single unique item for each id then you would only ever be able to correspond that item with a single size id.

Sign in to reply to this post

steven348539

Eric,

Sorry I haven't made myself clear. I've attached the small amount of data I've placed in the sizes table.

My thinking was, and as I said before if it's wrong you are welcome to correct me, that I have a column in the items table that relates to SizeCatID. So let's say an item has a 2 in the SizeID Column. In the sizes table, a 2 means that there is an 8x10 print for $15.00 available and a 16x20 print for $60.00 available.

Another item might have a 1 in the SizeID column, which means that only an 8x10 for $15.00 is available. (an 8x10 may not always be $15.00 which is why I'm listing a price in the table as well)

So, my idea was that whatever the ItemSize value was for an item it would then generate a drop box that listed all the options that were available for that Category based on the sizes table. I may be wrong as I'm not familar with SQL so I may have to change the tables around, which is fine. I want the most effective method and if I was wrong, well, wouldn't be the first time :lol:

Sign in to reply to this post

Eric Mittman

I think that the way you are wanting to do this should work so long as the the sizes table has multiple entries for a given category, one record for each size and price.

If this is the case then on the details page you would want to have a recordset like this:

SELECT items.SizeID, items.ItemID, sizes.*
FROM items JOIN sizes ON items.SizeID = sizes.SizeCatID
WHERE items.ItemID = <your item id>

This should work to create a recordset of size values for the given item. This is the way that you would want to do this if you only had the item's id available to you. If you had the size id from that item available then you could have a much simpler query, it would be like this:

SELECT * FROM sizes
WHERE sizes.SizeCatID = <the size id for the item>

This is probably the best way to go if you can pass along the size id with the item.

The first rs with the join must be crafted in the advanced view, but the second one can be created in the simple recordset view within DW. For the advanced one you would need to make a new SQL variable and then set it's value to the id for the item that is being passed. The simple view recordset can be configured with just some filtering based on the size id from a URL parameter or from a form post.

Sign in to reply to this post

steven348539

Eric,

That has worked will with the details page, though I've elected to do it with the more complex recordset as I don't want anyone to get the smart idea of changing the url to have access to sizes that aren't available for a print.

However, I can't get the proper price into the cart, it always selects the first price on the options list. I also can't get the options to work properly on the entire catalog page, it will repeat whatever the sizes were for the first item on the page.

For the moment, since we are several weeks into the hockey season and that's what some of these pictures are for, I've having to list out each size individually, which will get very cumbersome as I continue to add more pictures.

I'm feeling like an idiot trying to do this as I just cannot see the proper way to get it done easily.

Sign in to reply to this post

Eric Mittman

If it is always selecting the first price how are you setting the price for the column? Are you using a recordset lookup for the price? If so you will need a second rs on the page to get the accurate price. It would be like the first but it would filter based on the option selected from the select list on the page.

Getting this to work on your catalog page will be a little more difficult. You will essentially have to move the recordset into the loop on this page so that is pulls new fresh results for each item. On top of moving the rs you would also need to ensure that the reference you are using for the item that it is filtered on is updated as well.

Sign in to reply to this post

steven348539

Thanks Eric, that helped a lot as I got it working for the catalog page and the detail page now, plus I have it adding the correct price into the cart. At some point I'll need to add the ability to change it in the cart, but I have other things that need to be done first.

If you want to see, www.cis-portraits.com

Sign in to reply to this post

Eric Mittman

Nice work, let us know if you have any other questions about any part of this, we will be glad to help out.

Sign in to reply to this post
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...