tonylees Posted January 14, 2008 Share Posted January 14, 2008 HELP! I am in the process of creating a online shop selling kitchen cupboard doors, drawer fronts etc, BUT these are bespoke products that are not sold in a standard size! So I need the customer to be able to enter the height and the width and then the website provide the final price. Can anyone guide me in the right direction? I am a newbie to this so I apologize if this is basic information! Thanks for your help (in advance) Tony Quote Link to comment https://forums.phpfreaks.com/topic/86025-solved-how-do-i-create-a-cost-calculator/ Share on other sites More sharing options...
p2grace Posted January 14, 2008 Share Posted January 14, 2008 Since you're using a variable cost you're best bet is probably finding the total area and multiplying it by a per square inch cost to find a total cost. Simple example: $width = 16; $height = 35; $variable = .5; $area = $width * $height; $totalCost = $area * $variable; // will result in $280 for the door Quote Link to comment https://forums.phpfreaks.com/topic/86025-solved-how-do-i-create-a-cost-calculator/#findComment-439276 Share on other sites More sharing options...
tonylees Posted January 14, 2008 Author Share Posted January 14, 2008 Thanks for the quick reply. The cost wouldn't be variable as I can get a fixed price per sq mtr. (Would I put that in a database or can I just work with PHP?) How do I enter this in to my website? Thanks again Tony Quote Link to comment https://forums.phpfreaks.com/topic/86025-solved-how-do-i-create-a-cost-calculator/#findComment-439289 Share on other sites More sharing options...
p2grace Posted January 14, 2008 Share Posted January 14, 2008 A price per square meter is a variable cost, the variable being how many square meters you're buying, so the same theory applies. If the cost per square meter is ALWAYS the same you could just hard code it into php. However if the cost per square meter is different depending on the material being purchased, I'd recommend adding it into a database table. Quote Link to comment https://forums.phpfreaks.com/topic/86025-solved-how-do-i-create-a-cost-calculator/#findComment-439293 Share on other sites More sharing options...
revraz Posted January 14, 2008 Share Posted January 14, 2008 Also, know that prices will change for shipping over time, so account for that and choose a way that you can edit easily, like storing it in a DB. Quote Link to comment https://forums.phpfreaks.com/topic/86025-solved-how-do-i-create-a-cost-calculator/#findComment-439297 Share on other sites More sharing options...
p2grace Posted January 14, 2008 Share Posted January 14, 2008 revraz makes an excellent point, as far as keeping the system as easily to maintain as possible, having a database driven website is much more effective. Quote Link to comment https://forums.phpfreaks.com/topic/86025-solved-how-do-i-create-a-cost-calculator/#findComment-439298 Share on other sites More sharing options...
tonylees Posted January 14, 2008 Author Share Posted January 14, 2008 I think the database would be the best option. As I said I am New to all this so please be patient.... I have just attempted a quick script <label>Width <input type="text" name="textfield" /> <?php $width=""; ?> </label><br /> <label>Height <input type="text" name="textfield2" /><?php $height=""; ?> </label><br/> <label>Cost <input type="text" name="textfield3" /> </label> <?php $variable = 1; $area = $width * $height; $totalCost = $area * $variable; ?> Where am I going wrong? I have the text boxes that I can type the sizes in but i don't get any results Thanks Tony Quote Link to comment https://forums.phpfreaks.com/topic/86025-solved-how-do-i-create-a-cost-calculator/#findComment-439311 Share on other sites More sharing options...
revraz Posted January 14, 2008 Share Posted January 14, 2008 You didn't put in code to show a cost Also, that input area wont work for PHP, you need to submit it with a form to process it. $totalCost = $area * $variable; echo $totalCost; Quote Link to comment https://forums.phpfreaks.com/topic/86025-solved-how-do-i-create-a-cost-calculator/#findComment-439313 Share on other sites More sharing options...
ohdang888 Posted January 14, 2008 Share Posted January 14, 2008 I think the database would be the best option. As I said I am New to all this so please be patient.... I have just attempted a quick script <label>Width <input type="text" name="textfield" /> <?php $width=""; ?> </label><br /> <label>Height <input type="text" name="textfield2" /><?php $height=""; ?> </label><br/> <label>Cost <input type="text" name="textfield3" /> </label> <?php $variable = 1; $area = $width * $height; $totalCost = $area * $variable; ?> Where am I going wrong? I have the text boxes that I can type the sizes in but i don't get any results Thanks Tony you should use actaul names for the fields, makes less confusion... also, are you wanting to show them the cost on a new rpage, or on the same page? this is pretty much it.... i think. <?php if (isset($_POST['submit'])) { $width = $_POST["width"]; $height = $_POST["height"]; $variable = 1; $area = $width * $height; $totalCost = $area * $variable; echo 'Total Cost='; echo $totalCost; } ?> <form name="cost_finder" method="post"> <label>Width <input type="text" name="width" /> </label><br /> <label>Height <input type="text" name="height" /> </label><br/> <input type="submit" name="submit" value="Calculate Cost!"/> </form> Quote Link to comment https://forums.phpfreaks.com/topic/86025-solved-how-do-i-create-a-cost-calculator/#findComment-439320 Share on other sites More sharing options...
tonylees Posted January 15, 2008 Author Share Posted January 15, 2008 Thank you for you help, that is great! The results from the calculation appear at the top of the page, how can I control where the results are shown? Thanks again! what a fantastic community!! Tony Quote Link to comment https://forums.phpfreaks.com/topic/86025-solved-how-do-i-create-a-cost-calculator/#findComment-439596 Share on other sites More sharing options...
p2grace Posted January 15, 2008 Share Posted January 15, 2008 Do the calculations where they are, but move the echo statement to where you want it shown. Just remember that you need the "<?" and "?>" around the echo statement. Quote Link to comment https://forums.phpfreaks.com/topic/86025-solved-how-do-i-create-a-cost-calculator/#findComment-439996 Share on other sites More sharing options...
tonylees Posted January 15, 2008 Author Share Posted January 15, 2008 Is it possible to change the font type, size and colour for the result? Thanks Tony Quote Link to comment https://forums.phpfreaks.com/topic/86025-solved-how-do-i-create-a-cost-calculator/#findComment-440073 Share on other sites More sharing options...
p2grace Posted January 15, 2008 Share Posted January 15, 2008 Of course, when you use echo you're actually printing html code. Simple Example: // All you calculations were done above echo "<p style=\"color: #ccc; font-weight: bold;\">$totalCost</p>"; // you can have whatever styles you want. You can display any html, just remember to escape double quotes Quote Link to comment https://forums.phpfreaks.com/topic/86025-solved-how-do-i-create-a-cost-calculator/#findComment-440076 Share on other sites More sharing options...
revraz Posted January 15, 2008 Share Posted January 15, 2008 Next step, learn CSS. Quote Link to comment https://forums.phpfreaks.com/topic/86025-solved-how-do-i-create-a-cost-calculator/#findComment-440077 Share on other sites More sharing options...
tonylees Posted January 15, 2008 Author Share Posted January 15, 2008 Thanks everyone for your fantastic help!! I'll try not to bother you all too much Quote Link to comment https://forums.phpfreaks.com/topic/86025-solved-how-do-i-create-a-cost-calculator/#findComment-440100 Share on other sites More sharing options...
p2grace Posted January 15, 2008 Share Posted January 15, 2008 If everything works, could you mark the post as "Topic Solved" Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/86025-solved-how-do-i-create-a-cost-calculator/#findComment-440102 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.