This code works but i want to add all the total costs up at the bottom of the search output, the // Loop through data and display is outputs displayed from MySQL, from this code all i get is the total price for each booking but i want to add each booking to display the overall price. So if anyone could help me i would be grateful as its my final year project thank u.

?>
 <center>
 <table border="0" width="75%"> 
 <td><center><hr>Day<hr></center></td>
 <td><center><hr>Booking dates<small>(From and to)</small><hr></center></td>
 <td><center><hr>TotalPrice (£)<hr></center></td>
 </tr>
 </center>
<?

// Loop through data and display
while($a_row= mysql_fetch_assoc($result))
	echo "<tr><td style=\"color:Black\">".$a_row['DayofWeek']."</td>".
	     "<td style=\"color:Black\">".$a_row['Bookingdate']."</td>".
             "<td style=\"color:red\">".$a_row['Total']."</td></tr>"; 
             
// Close connection ! (please !)
mysql_close($connection);

?>

Recommended Answers

All 5 Replies

Have another variable which adds $a_row value.

$sum=0;
while($a_row= mysql_fetch_assoc($result)) {
echo "<tr><td style=\"color:Black\">".$a_row['DayofWeek']."</td>".
"<td style=\"color:Black\">".$a_row['Bookingdate']."</td>".
"<td style=\"color:red\">".$a_row['Total']."</td></tr>";
$sum=$sum+$a_row['Total'];
}

By the end of the loop, $sum will have the total of $a_row.

still dont display overall price??

<?

// Retrieve value from form
$value1 = $_POST['date1'];
$value2 = $_POST['date2'];


// Depending on days entered work out total price for each day of the week, shows which day makes the most income
$sql = "SELECT DayofWeek, Bookingdate,  SUM( TotalPrice ) AS Total
FROM InstructorKellyFox
WHERE Bookingdate
BETWEEN '$value1'
AND '$value2'
GROUP BY DayofWeek DESC";


// Retrieve the data
$result = mysql_query($sql, $connection);

?>
 <center>
 <table border="0" width="75%"> 
 <td><center><hr>Day<hr></center></td>
 <td><center><hr>Booking dates<small>(From and to)</small><hr></center></td>
 <td><center><hr>TotalPrice (£)<hr></center></td>
 </tr>
 </center>
<?

// Loop through data and display
$sum=0;
while($a_row= mysql_fetch_assoc($result)) {
echo "<tr><td style=\"color:Black\">".$a_row
['DayofWeek']."</td>".
"<td style=\"color:Black\">".$a_row['Bookingdate']."</td>".
"<td style=\"color:red\">".$a_row['Total']."</td></tr>";
$sum=$sum+$a_row['Total'];
} 
             
// Close connection ! (please !)
mysql_close($connection);

?>

hello it dnt vvork ive posted it again can u help please

during each while loop, print out what's in $sum.

while($a_row= mysql_fetch_assoc($result)) {
echo "<tr><td style=\"color:Black\">".$a_row
['DayofWeek']."</td>".
"<td style=\"color:Black\">".$a_row['Bookingdate']."</td>".
"<td style=\"color:red\">".$a_row['Total']."</td></tr>";
$sum=$sum+$a_row['Total'];
echo $sum;
}

THANK U

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.