philb Posted August 20, 2013 Share Posted August 20, 2013 (edited) Very new to this and trying to adapt some code so that I can print the sum of a variable in a loop. If anyone can assist I would be eternally grateful. I want to add the values of (integer) $pax_number, then print out that total after the loop has stopped. Here's the page: http://www.availabilities.co.uk/hdhc9.php And here's the code: <? //Change Today's date to any date in the future $tomorrow = mktime(0,0,0,date("m"),date("d")+4,date("Y")); echo "BOOKINGS FOR DATE: " .date("d-m-Y", $tomorrow); $SQL = "SELECT * FROM tables WHERE booking_date= '" .date("Y-m-d", $tomorrow). "' ORDER BY booking_date ASC, time ASC"; //Shows bookings from a specific date only $recordSet = &$conn->Execute($SQL); if ($conn->ErrorNo() > 0) print "<hr><pre>An error occurred searching the database!<br>Error Msg: ".$conn->ErrorMsg()."</pre><hr>"; elseif (!$recordSet->EOF && isset($recordSet->fields[0])) { while (!$recordSet->EOF) { $ff_id=$recordSet->fields("ff_id"); $book_cancel=$recordSet->fields("book_cancel"); $booking_date=$recordSet->fields("booking_date"); $pax_number=$recordSet->fields("pax_number"); $time=$recordSet->fields("time"); $room=$recordSet->fields("room"); $name=$recordSet->fields("name"); $tel_number=$recordSet->fields("tel_number"); $email=$recordSet->fields("email"); $voucher_type=$recordSet->fields("voucher_type"); $voucher_number=$recordSet->fields("voucher_number"); $notes=$recordSet->fields("notes"); //Format the date $format=("l F jS Y"); $date2 = date($format, strtotime($booking_date)); // PRINT TO SCREEN - table.css print ' <div class="product_item"> <h4>ID: '.$ff_id.' - Date: '.$date2.' - Time: '.$time.' - Room: '.$room.' - No. of Persons: '.$pax_number.'</font></h4> <hr /> <h5>Name: '.$name.' - Tel: '.$tel_number.' - Voucher: '.$voucher_type.' - '.$voucher_number.'</font></h5> <h5>Notes: '.$notes.'</font></h5> <div style="clear:both"></div> </div> '; $recordSet->MoveNext(); } } ?> Edited August 20, 2013 by Zane Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted August 20, 2013 Share Posted August 20, 2013 (edited) Here is a brief example how it works: $count = array(); $i = 0; while ($i < 10) { $count[] = $i; $i++; } // print out the results echo '<pre>'.print_r($count, true).'</pre>'; echo count($count); In your example let the $pax_number to be an array and count all results. Edited August 20, 2013 by jazzman1 Quote Link to comment Share on other sites More sharing options...
philb Posted August 20, 2013 Author Share Posted August 20, 2013 Hmmmmmmmmmm.... I really appreciate your assistance, and I understand this - but it's not relevant to the existing code. There's already a loop going on, so I presume that I don't need another 'while'... And the integer $pax_number already has (different) a value (each the time the loop iterates)... So I have no idea how I can integrate this... Any more help would be much appreciated. Thanks. Phil... Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted August 20, 2013 Share Posted August 20, 2013 Create a new empty array, for instance $count_pax_number and put inside it every value of $pax_number, then print out that total after the loop has stopped. Take a look at my example above and use the same logic. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.