Help with php base (2)
This is an extension of the question I had yesterday.
I am trying to make a small php calculator that will show how much people can save on their phone bills if they switch to VoIP, and how much they can save with each service.
I have a form that spits out the correct amount for a monthly invoice here:
http://www.nextadvisor.com/voip_services/voip_calculator.php?monthlybill=50&Submit=Submit
But now I need to integrate this with some other data and put it into a table. The prices for each of the different services are in a different file called "values.php". Values:
$offer1calcsavings="24.99";
$offer2calcsavings="20.00";
$offer3calcsavings="21.95";
$offer4calcsavings="23.95";
$offer5calcsavings="19.95";
$offer6calcsavings="23.97";
$offer7calcsavings="24.99";
I want each of the seven rows of the table to have one of the values ββof the calcsavings clause subtracted from the MonthlyBill value.
The php code currently looks like this:
<?php $monthlybill = $_GET['monthlybill']; ?>
Your monthly bill was <?php echo "$monthlybill"; ?>
<?php
$monthybill="monthlybill";
$re=1;
$offer ='offer'.$re.'name';
$offername= ${$offer};
while($offername!=""){
$offerlo ='offer'.$re.'logo';
$offerlogo=${$offerlo};
$offerli ='offer'.$re.'link';
$offerlink=${$offerli};
$offeran ='offer'.$re.'anchor';
$offeranchor=${$offeran};
$offerst ='offer'.$re.'star1';
$offerstar=${$offerst};
$offerbot='offer'.$re.'bottomline';
$offerbottomline=${$offerbot};
$offerca ='offer'.$re.'calcsavings';
$offercalcsavings=${$offerca};
echo '<tr >
<td >
<a href="'.$offerlink.'" target="blank">
<img src="http://www.nextadvisor.com'.$offerlogo.'" alt="'.$offername.'" />
</a>
</td>
<td ><span class="rating_text">Rating:</span>
<span class="star_rating1">
<img src="http://www.nextadvisor.com'.$offerstar.'" alt="" />
</span><br />
<div style="margin-top:5px; color:#0000FF;">
<a href="'.$offerlink.'" target="blank">Go to Site</a>
<span style="margin:0px 7px 0px 7px;">|</span>
<a href="'.$offeranchor.'">Review</a>
</div> </td>
<td >'.$offercalcsavings.'</td>
</tr>';
$re=$re+1;
$offer ='offer'.$re.'name';
$offername= ${$offer};
}
?>
source to share
I want each of the seven rows of the table to have one of the Calculate values ββfrom the monthly value.
You need to do the math somewhere. Presumably you will do this before the echo statement, where you will output your string.
$offerwithsavings = $monthlybill - $offercalcsavings
Then just remember to include it in your spreadsheet somewhere.
<td >'.$offerwithsavings.'</td>
The real recipe for this code is an array and foreach () loop, but I thought I'd keep my answer simple for now. Array outlines and foreach () are very powerful and relatively fast and easy to learn. You should give them an in-depth study.
source to share
You can include the values.php file like this:
include 'path/to/values.php';
If you put the values ββin values.php into an array, you can easily loop them through the foreach:
in values.php;
$values['1calsavings'] = 24.99;
$values['2calsavings'] = 20.00;
etc;
Then in another file:
include 'path/to/values.php';
foreach($values as $name => $amount){
echo '<some_markup>';
echo "$name $amount";
echo '</some_markup>';
}
source to share