I’m trying to create a form that will create a table of pricing for t-shirts.
There are 10 shirts to choose from and each one is a different price. The S through XL are the same price but the XXL is a different price.
Next there is a selection for the color of the garment which also varys the price and there are 3 options White, Athletic, and Color.
The 3rd selection is the number of colors in the print for the shirt. Which there are 5 options (1-2, 3-4, 5-6, 7-8, 9-10 which affects the price.
Then I also have a few checkboxes which are add-ons that add to the price also.
The final data I want to show is a 2 row table showing in each column the price for 48pc, 72pc, 96pc, 144pc, 288pc. The first row will be the price for S-XL and the 2nd row would be for the XXL price.
I’ve created a super huge file that does the calculations and comes up with a cost but I know there is a easier way and a correct way that what I did. How would you guys do a file like this and can anyone help me out? I’m about to go crazy I been working on it for the past week and half straight.
I didn’t post it because it was to long. I uploaded it to gitHub though heres the link:
https://gist.github.com/1708558GitHub
You are right, there is an easier way – you can write a php script that will generate all this code automatically!
For example, you create in your MySQL DB a table that will hold the < key,val > of all the shirts:
< DT0001 , DT0001SHIRTCOLOR >
< DT000161 , DT000161SHIRTCOLOR >
…
and then you read the data from your PHP script and print/echo, for example:
You can do this with most of your code and avoid duplication. In general, whenever you copy & paste your code and change only the parameters – you should think about creating a generalized method that will get the parameters as input and will generate the code you wanted to copy (this principle is called “code re-use”).
Hope I helped.