Jump to content

Add 2 variables together


chrispos

Recommended Posts

I'm having a prob with adding 2 variables together to show on every row.

 

The $total takes the first total and only adds that to the second total.

$query = "SELECT * FROM `price`WHERE`month` = 4 AND `year` = 2009";
$result = mysql_query($query) or die (mysql_error());
if (mysql_num_rows($result)>0){ 
while ($row = mysql_fetch_row($result)) {
$pid = $row[0];
$hid1 = $row[1];
$rid1 = $row[2];
$number1 = $row[3];
$rmonth = $row[4];
$ryear = $row[5];
$price1 = $row[6];
$firstprice = $montha * $price1;
echo"$number1\n\n";
echo"$price1<br><br>";
echo "$firstprice<br><br>";
}
}
$query = "SELECT * FROM `price`WHERE`month` = 5 AND `year` = 2009";
$result = mysql_query($query) or die (mysql_error());
if (mysql_num_rows($result)>0){ 
while ($row = mysql_fetch_row($result)) {
$pid = $row[0];
$hid1 = $row[1];
$rid1 = $row[2];
$number1 = $row[3];
$rmonth = $row[4];
$ryear = $row[5];
$price2 = $row[6];
$firstprice1 = $month2 * $price2;
$total = $firstprice + $firstprice1;
echo"$number1\n\n";
echo"$price2<br><br>";
echo "$firstprice1<br><br>";
echo "$total<br><br>";

}
}

 

the monthly price has been inserted into just one table the first month price works fine the second month price works fine it is just the totals that take just the first total and adds that

 

 

Link to comment
https://forums.phpfreaks.com/topic/151642-add-2-variables-together/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.