thomashw Posted January 8, 2008 Share Posted January 8, 2008 The website I'm currently making will have multiple product pages (for different products.) A single product page may have multiple drop down form fields, in which depending on what the user selects I want the price to be changed accordingly. I think I've thought of a way to do it, but I'm not sure how to implement it. I could add each variance of the product to my database, and then basically "match" what the user selects to what's in my database to call the specific price. Does that make sense? Here's an example: I add Product 1 to my database. It has two options, so it gets a unique ID in the table. The options are to have it in small or medium. Small costs $15 and medium costs $20. The table has the rows "product_spec_id (Primary) | size | price | product_id." The two options will have the same product_id. When the user selects medium and clicks purchase, the table will be "searched" and matched up with whatever entry matches the selections of the user - which then extracts that price. Is this possible? Or is there an easier way? I could potentially make a seperate page for each option, but that's just messy/slow. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/85026-solved-using-forms-with-php/ Share on other sites More sharing options...
revraz Posted January 8, 2008 Share Posted January 8, 2008 Sounds easy enough and very doable. Quote Link to comment https://forums.phpfreaks.com/topic/85026-solved-using-forms-with-php/#findComment-433596 Share on other sites More sharing options...
thomashw Posted January 8, 2008 Author Share Posted January 8, 2008 That's what I was hoping to hear! Hmm... has anyone heard of any other ways to do it, too? Quote Link to comment https://forums.phpfreaks.com/topic/85026-solved-using-forms-with-php/#findComment-433604 Share on other sites More sharing options...
nikefido Posted January 8, 2008 Share Posted January 8, 2008 I would make a second table for the prices - this is more normalized (which is important to database structure, especially with scaling issues)... The first table would be your product ID and information. The second table would have it's own unique ID and also the foreign Key from the product table table PRODUCT: product_id, product_name, product_descr (etc...) table PRICES: price_id, product_id, product_price, product_variable (you can use product variable to set "medium, large, small" etc etc --after reading your post again, it looks like we might be saying the same thing, yes? Using two tables? --also, you might want to check out osCommerce (free open source e-Commerce) to see how they set up their tables - could be very useful for you! Quote Link to comment https://forums.phpfreaks.com/topic/85026-solved-using-forms-with-php/#findComment-433614 Share on other sites More sharing options...
thomashw Posted January 8, 2008 Author Share Posted January 8, 2008 I actually hadn't thought to use two tables. That's definitely better though, or else I'd be typing out a lot of the same information for each product. And I actually do have oscommerce installed, and have been looking at it. Now... I just have to figure out how to do this. How can I use PHP to call the row that "matches" the users selection? Quote Link to comment https://forums.phpfreaks.com/topic/85026-solved-using-forms-with-php/#findComment-433624 Share on other sites More sharing options...
nikefido Posted January 8, 2008 Share Posted January 8, 2008 look up a SQL JOIN - i think that should get you in the right direction (can select columns from different tables an get them in one result set) Otherwise you can use two different queries, one to the products table, one to the 2nd table. Quote Link to comment https://forums.phpfreaks.com/topic/85026-solved-using-forms-with-php/#findComment-433628 Share on other sites More sharing options...
thomashw Posted January 8, 2008 Author Share Posted January 8, 2008 Does anyone have any suggestions of books I can buy that will go over implementing products onto a website? Specifically I need help with actually setting up their prices, etc. This situation has gotten me highly confused on what to do, as some products have a ton of "variables" while some have none, or one, or two, etc. I'd like to use drop-down forms, but I don't think I can make it work properly with a database. Any book ideas/other ideas? Quote Link to comment https://forums.phpfreaks.com/topic/85026-solved-using-forms-with-php/#findComment-433708 Share on other sites More sharing options...
revraz Posted January 8, 2008 Share Posted January 8, 2008 Go to amazon.com and search for books that have PHP and MYSQL in the title, you'll get a ton of results. There is one that is pretty cheap and is a good starter book, How to do Everything with PHP & MySQL. Pick up a MySQL book if you want to learn how to do things like JOINS. Quote Link to comment https://forums.phpfreaks.com/topic/85026-solved-using-forms-with-php/#findComment-433711 Share on other sites More sharing options...
thomashw Posted January 8, 2008 Author Share Posted January 8, 2008 Well I've got a few books that apply to PHP/MySQL, but I'm just not sure how I should be going about doing this precise thing... Quote Link to comment https://forums.phpfreaks.com/topic/85026-solved-using-forms-with-php/#findComment-433718 Share on other sites More sharing options...
revraz Posted January 8, 2008 Share Posted January 8, 2008 This might help http://www.phpfreaks.com/forums/index.php/topic,126097.0.html Quote Link to comment https://forums.phpfreaks.com/topic/85026-solved-using-forms-with-php/#findComment-433720 Share on other sites More sharing options...
br0ken Posted January 8, 2008 Share Posted January 8, 2008 The way I've done it is to have one table called tblProduct and two others, tblFeatureItem, tblFeatureGroup. tblFeatureGroup has many featureItems in it. For example there could be a featureGroup called colour which has the items red, green and blue. Each item has aprice associated with it. Now each product is associated with a feature group which is then associated with several featureItems. So we have 'Product A' which has the featureGroup 'Colours' which has the featureItems 'red', 'blue' and 'green'. When someone buys the product you create a record in tblOrder. Then in tblOrderProduct we create a record for each item purchased which contains the product ID, the order ID, the quantity, the featureItem ID and the overall price (featureItem price + proudct price) Sorry for how rushed this is but if you've got any questions let me know and I'll be happy to help out! Quote Link to comment https://forums.phpfreaks.com/topic/85026-solved-using-forms-with-php/#findComment-433961 Share on other sites More sharing options...
thomashw Posted January 8, 2008 Author Share Posted January 8, 2008 That's awesome. MUCH better than the way I had been trying to do it - which made it overly complicated. I'll try this - I think it'll work perfectly for what I need. Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/85026-solved-using-forms-with-php/#findComment-433964 Share on other sites More sharing options...
br0ken Posted January 8, 2008 Share Posted January 8, 2008 I have another table called tblDelivery with the fields id, name, price and notes. To record a delivery type I add a record to tblOrderProduct. To differentiate between products and delivery types, I've set a maximum quantity for any item at 99 and I then give a quantity of 100 to a delivery item. This way I can tell which items are products and which are delivery items. I also do this with vouchers. Quote Link to comment https://forums.phpfreaks.com/topic/85026-solved-using-forms-with-php/#findComment-434008 Share on other sites More sharing options...
thomashw Posted January 8, 2008 Author Share Posted January 8, 2008 How do you calculate your shipping charges? Quote Link to comment https://forums.phpfreaks.com/topic/85026-solved-using-forms-with-php/#findComment-434011 Share on other sites More sharing options...
br0ken Posted January 8, 2008 Share Posted January 8, 2008 I have another table called tblDelivery with the fields id, name, price and notes. To record a delivery type I add a record to tblOrderProduct. To differentiate between products and delivery types, I've set a maximum quantity for any item at 99 and I then give a quantity of 100 to a delivery item. This way I can tell which items are products and which are delivery items. I also do this with vouchers. I call Shipping Charges Delivery charges but it's the same thing! Quote Link to comment https://forums.phpfreaks.com/topic/85026-solved-using-forms-with-php/#findComment-434018 Share on other sites More sharing options...
thomashw Posted January 8, 2008 Author Share Posted January 8, 2008 I have another table called tblDelivery with the fields id, name, price and notes. To record a delivery type I add a record to tblOrderProduct. To differentiate between products and delivery types, I've set a maximum quantity for any item at 99 and I then give a quantity of 100 to a delivery item. This way I can tell which items are products and which are delivery items. I also do this with vouchers. I call Shipping Charges Delivery charges but it's the same thing! Oh, I know I'm just not seeing how they're "calculated" on an item-to-item basis. Quote Link to comment https://forums.phpfreaks.com/topic/85026-solved-using-forms-with-php/#findComment-434021 Share on other sites More sharing options...
br0ken Posted January 8, 2008 Share Posted January 8, 2008 Each record in tblDelivery has a cost specified with it. This is added as an item to the tblOrderProduct. The tblDelivery id goes in the productID field, the orderID and price is normal, the featuureItemID is NULL. The quantity is larger than 99 again. I then have a function that gets all records from tblOrderProduct with a certain order ID. It then goes through each record and depending on the quantity does a different task. Is this what you were looking for? If not can you please be more specific. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/85026-solved-using-forms-with-php/#findComment-434027 Share on other sites More sharing options...
thomashw Posted January 8, 2008 Author Share Posted January 8, 2008 That's perfect. I just wasn't sure how I should add the delivery costs in there as well. Thank you! You've been a HUGE help! Quote Link to comment https://forums.phpfreaks.com/topic/85026-solved-using-forms-with-php/#findComment-434032 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.