I have a problem with this script and don't know if I should be using an array. I am trying to get a total adding 2 rows together making a total and then that total showing in every row. The totals are prices in a hotel booking form. I have added $firstprice and $ firstprice1 all the prices work but the problem comes because when i get a total it only adds the first row from $firstprice to every row in $firstprice1. i would like it to add every row in $firstprice to every row in $firstprice1 so that each room has the correct 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 prices are all stored in one table named price
Thanks for your time and help