CALCULATOR USING PHP - Jan 5th, 2012


There are may approaches to creating calculators using JavaScript and other approaches. Here’s one that I put together
for a Gicleé printing company that uses fairly simple PHP programming.

Dimensional values in the pull down lists are taken from a multi-record list of standard print dimensions using the
getListOptions function where “dimensions” is the name of the table and “value2" is the name of the field holding
the numerical value.

Pricing values are taken from a multi-record list of information about each of the papers that the company utilizes.
Each record contains a field for manufacturer, media family, media weight and price.

The form displays pull down list of $label values made up of the values of the record’s fields: manufacturer, media
family and media weight. The value of the record’s price field is used for the option value.

The formula used is (standard length in inches x standard height in inches)/144) * price per square foot = $value.

A reset form is included at the end.



<form method="POST" action="<?php echo $_SERVER['PHP_SELF'] ?>" >
<select name = "price" >
<option value="">Choose A Paper Type From This List</option>
<?php foreach ($print_mediaRecords as $record): ?>
<?php $label = @$record['manufacturer:label'] . " ". @$record['media_family'] . " ". @$record['media_weight'] ." lbs"
?>
<option value = "<?php echo(@$record['price']);?>" label="<?php echo($label) ?>">
<?php echo $label; ?></option>
<?php endforeach ?>
</select>
<br /> <br />
<span class="body-text-9">The dimensions listed are our standard printing dimensions. Your actual print dimensions can't
be larger than the ones you choose.</span>
<br /> <br />
<select name='input1'>
<option value="">Choose Your First Dimension (Length Or Width)</option>
<?php foreach (getListOptions('dimensions','value2') as $value => $label): ?>
<option value = "<?php echo $value;?>" <?php selectedIf($value, @$_REQUEST['value2']);?>>
<?php echo $label; ?></option>
<?php endforeach ?>
</select>
<br /> <br />
<select name='input2'>
<option value="">Choose Your Second Dimension</option>
<?php foreach (getListOptions('dimensions','value2') as $value => $label): ?>
<option value = "<?php echo $value;?>" <?php selectedIf($value, @$_REQUEST['value2']);?>>
<?php echo $label; ?></option>
<?php endforeach ?>
</select>
<br /> <br />
<input type="submit" name="submit" value="Click To Calculate The Cost Of Your Print" >
</form>
<br />
<?PHP

//The calculation
$value = ((@$_POST['input1'] * @$_POST['input2'])/144) * @$_POST['price'] ;
?>
<span class="body-text-bold-9">Cost For Each Print:</span>
<span class="body-text-9">$
<?PHP
//Output result
echo number_format($value ,2) ?>
<br />
<span class=" body-text-bold-red-9">**</span> <span class="body-text-9">Print Prices are approximate, if adjustments of
more than 10% are required, we will notify you prior to proceeding.</span>
<br /> <br />
<FORM ACTION="">
<INPUT TYPE="submit" VALUE="Reset Form and Calculate Another Print Cost">
</FORM>



The materials on this web site have been created for use with CMS Builder content management software. CMS Builder software is published and licensed for use by InteractiveTools.com. Please contact Interactive Tools for information on the downloading of the software or the purchasing of licenses.


Terms of Service