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
Building estimate form
Old 12-09-2008, 02:39 PM Building estimate form
Novice Talker

Posts: 6
Trades: 0
I need some help building a form to provide an instant estimate. As I worked through the code I got stuck. The client has a spread sheet of all the prices. He prints CDs. So he has choices for:

CD quantity: 1-100, 101-200 and so on...
5 choices of labeling colors
5 choices of packaging
3 choices of printing

I get stuck becuase each level of CD quantity gives a different price break. Here is what I have so far. I have a page for the form.
PHP Code:
<form name="form1" id="form1" method="post" action="calculate.php">
  <
table width="217" border="1" cellspacing="0" cellpadding="0">
    <
tr>
      <
td width="114">CD</td>
      <
td width="573"><input name="cdQuantity" type="text" id="cdQuantity" /></td>
    </
tr>
    <
tr>
      <
td>Labelling</td>
      <
td><select name="cdLabel" id="cdLabel">
        <
option value="0">None</option>
        <
option value=".10">Black on silver</option>
        <
option value=".20">Black on white</option>
        <
option value=".30">Color on Silver</option>
        <
option value=".40">Color on white</option>
      </
select></td>
    </
tr>
    <
tr>
      <
td>Packaging</td>
      <
td><select name="cdPackage" id="cdPackage">
        <
option value="0">Bulk</option>
        <
option value=".03">Paper Envelope</option>
        <
option value=".23">Clam Shell</option>
        <
option value=".25">Slim Jewel Case</option>
        <
option value=".38">Full Jewl Case</option>
        <
option value=".75">DVD Box</option>
      </
select></td>
    </
tr>
    <
tr>
      <
td>Printing</td>
      <
td><select name="cdPrint" id="cdPrint">
        <
option value="0">None</option>
        <
option value="1.00">Slim Jewel Case Top</option>
        <
option value=".85">Full Jewel case Top and Back</option>
      </
select></td>
    </
tr>
       <
tr>
      <
td><input type="submit" name="Submit" value="Submit" /></td>
      <
td>&nbsp;</td>
    </
tr>
  </
table>
</
form
And here is the page that calculates:

PHP Code:
<?php 
// address error handling.
ini_set ('display_errors',1);
error_reporting (E_ALL & ~E_NOTICE);
$cdQuantity $_POST['cdQuantity'];
$cdLabel $_POST['cdLabel'];
$cdPackage $_POST['cdPackage'];
$cdPrint $_POST['cdPrint'];
//Calculate the individual price.
$price $cdLabel $cdPackage $cdPrint;
//Calculate total price.
$total $cdQuantity $price;
//Print out results.
print "You have selected to order:</br>
$cdQuantity CDs at $$price. Your estimated cost is $$total.";
?>
mallen is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-10-2008, 03:59 AM Re: Building estimate form
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
PHP Code:
if ($quantity 0) {
   if (
$quantity 101) {
      
$price 100;
   }
   elseif (
$quantity 201) {
      
$price 90;
   }
   ...

__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 12-10-2008, 03:49 PM Re: Building estimate form
Novice Talker

Posts: 6
Trades: 0
Thanks mtishetsky for your reply. I follow what you are doing but there are more variables to consider. Not only the quantity but 5 price points for lableing, 5 price points for packaging and printing.
mallen is offline
Reply With Quote
View Public Profile
 
Old 12-13-2008, 03:12 PM Re: Building estimate form
Novice Talker

Posts: 6
Trades: 0
I revised the code but still can't get it to work. Here is the part of the form. I assigned 1,2,3 or 4 to keep it simple.
PHP Code:
        <select name="cdLabel" id="cdLabel">
        <
option value="0">None</option>
        <
option value="1">Black on silver</option>
        <
option value="2">Black on white</option>
        <
option value="3">Color on Silver</option>
        <
option value="4">Color on white</option>
      </
select></td
Here is the page that calculates.
PHP Code:
<?php 
// address error handling.
ini_set ('display_errors',1);
error_reporting (E_ALL & ~E_NOTICE);


$cdQuantity $_POST['cdQuantity'];
$cdLabel $_POST['cdLabel'];
$cdPackage $_POST['cdPackage'];
$cdPrint $_POST['cdPrint'];
//calculate the individual price.

if ($cdLabel )  {
   
$price 8.00;
   
$blkslv 0;
   
$blkwht 0.1;
   
$colsil 0.5;
   
$colorwhite 0.6;

if (
$cdLabel )  {
   
$price 7.00;
   
$blkslv 0;
   
$blkwht 0.1;
   
$colsil 0.5;
   
$colorwhite 0.6
   
if (
$cdLabel )  {
   
$price 6.00;
   
$blkslv 0;
   
$blkwht 0.1;
   
$colsil 0.5;
   
$colorwhite 0.6;
   
if (
$cdLabel ) {
   
$price 5.00;
   
$blkslv 0;
   
$blkwht 0.1;
   
$colsil 0.5;
   
$colorwhite 0.6;
   
 if (
$cdLabel )  {
   
$price 3.00;
   
$blkslv 0;
   
$blkwht 0.08;
   
$colsil 0.4;
   
$colorwhite 0.45;
   
 if (
$cdLabel )  {
   
$price 2.00;
   
$blkslv 0;
   
$blkwht 0.07;
   
$colsil 0.4;
   
$colorwhite 0.45
   
if (
$cdLabel  )  {
   
$price 1.50;
   
$blkslv 0;
   
$blkwht 0.06;
   
$colsil 0.35;
   
$colorwhite 0.4;
   
if (
$cdLabel  ) {
   
$price 1.15;
   
$blkslv 0;
   
$blkwht 0.06;
   
$colsil 0.35;
   
$colorwhite 0.4;
   
if (
$cdLabel  )  {
   
$price .75;
   
$blkslv 0.02;
   
$blkwht 0.05;
   
$colsil 0.3;
   
$colorwhite 0.35;
   
if (
$cdLabel  10 ) {
   
$price .60;
   
$blkslv 0.02;
   
$blkwht 0.05;
   
$colsil 0.2;
   
$colorwhite 0.22;              
     }
        }
        }
        }
        }
        }
        }
        }
        }
    }


$subprice $price $blkslv $blkwht $colsil $colorwhite;
//calculate total price.
$total $subprice $cdQuantity;

//print out results.
print "You have selected to order:</br>
$subprice CDs at $cdQuantity. Your estimated cost is $total.";

?>
mallen is offline
Reply With Quote
View Public Profile
 
Old 12-13-2008, 05:38 PM Re: Building estimate form
stoot98's Avatar
Ultra Talker

Posts: 427
Name: Stuart
Location: Glasgow, Scotland
Trades: 0
You have a very strange, and flawed, If block structure. They are all nested so the CD Label 10 block will only get executed if it also equal all of the other possible numbers which cant happen. This should be done as a switch statement like this:

PHP Code:

<?php 
// address error handling.
ini_set ('display_errors',1);
error_reporting (E_ALL & ~E_NOTICE);


$cdQuantity $_POST['cdQuantity'];
$cdLabel $_POST['cdLabel'];
$cdPackage $_POST['cdPackage'];
$cdPrint $_POST['cdPrint'];
//calculate the individual price.

switch( $cdLabel )
{
    case 
1:
       
$price 8.00;
       
$blkslv 0;
       
$blkwht 0.1;
       
$colsil 0.5;
       
$colorwhite 0.6;
       break;
      
    case 
2:
       
$price 7.00;
       
$blkslv 0;
       
$blkwht 0.1;
       
$colsil 0.5;
       
$colorwhite 0.6
       break;

    case 
3:
       
$price 6.00;
       
$blkslv 0;
       
$blkwht 0.1;
       
$colsil 0.5;
       
$colorwhite 0.6;
       break;
   
    case 
4:
       
$price 5.00;
       
$blkslv 0;
       
$blkwht 0.1;
       
$colsil 0.5;
       
$colorwhite 0.6;
       break;
       
     case 
5:
       
$price 3.00;
       
$blkslv 0;
       
$blkwht 0.08;
       
$colsil 0.4;
       
$colorwhite 0.45;
       break;
   
     case 
6:
       
$price 2.00;
       
$blkslv 0;
       
$blkwht 0.07;
       
$colsil 0.4;
       
$colorwhite 0.45
       break;
       
    case 
7:
       
$price 1.50;
       
$blkslv 0;
       
$blkwht 0.06;
       
$colsil 0.35;
       
$colorwhite 0.4;
       break;
       
    case 
8:
       
$price 1.15;
       
$blkslv 0;
       
$blkwht 0.06;
       
$colsil 0.35;
       
$colorwhite 0.4;
       break;
       
    case 
9:
       
$price .75;
       
$blkslv 0.02;
       
$blkwht 0.05;
       
$colsil 0.3;
       
$colorwhite 0.35;
       break;
       
    case 
10:
       
$price .60;
       
$blkslv 0.02;
       
$blkwht 0.05;
       
$colsil 0.2;
       
$colorwhite 0.22;              
       break;
}



$subprice $price $blkslv $blkwht $colsil $colorwhite;
//calculate total price.
$total $subprice $cdQuantity;

//print out results.
print "You have selected to order:</br>
$subprice CDs at $cdQuantity. Your estimated cost is $total.";

?>
This isnt tested and i always forget the switch syntax but along the correct lines at least!
stoot98 is offline
Reply With Quote
View Public Profile
 
Old 12-14-2008, 09:09 PM Re: Building estimate form
Novice Talker

Posts: 6
Trades: 0
stoot98 thanks for the help! I new I needed something like that just couldn't figure it out. Now that part is working my calculation is off. See that if they choose case 1:

$blkslv = 0;
$blkwht = 0.1;
$colsil = 0.5;
$colorwhite = 0.6;
break;

It is adding up all five choices of color choices when in reality they will only be choosing one. So I need a way to calculate just one choice. Would any array do this?

Also I removed $price. The quanity is entered into a text box. And price is determined by quanity such as 1-10 copies for $8.00, 11-24 for $7.00
So I need a swtch statement for that I guess?

Last edited by mallen; 12-15-2008 at 02:07 PM..
mallen is offline
Reply With Quote
View Public Profile
 
Old 12-15-2008, 09:10 PM Re: Building estimate form
Novice Talker

Posts: 6
Trades: 0
Here is a picture of the price chart to see what i am trying to do.

mallen is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Building estimate form
 

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.25789 seconds with 12 queries