Jump to content

Count++ (maybe!) Problem...


philb

Recommended Posts

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 by Zane
Link to comment
Share on other sites

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 by jazzman1
Link to comment
Share on other sites

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...

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.