View Full Version : How to separate pages using php?
chleng
06-11-2005, 01:05 PM
Hi, I tasked to generate a bill using php.
The sample bill looks like this
billing name :abc
account no:12345
summary
9111 1111
9222 2222
Details
mobile number 9111 1111
number of outgoing calls 29
number of sms 30
mobile number 9111 1111
mobile number 9222 2222
number of outgoing calls 29
number of sms 30
but since the details portion is variable how to I separate the pages? thks
bithead
06-20-2005, 10:36 AM
What are you trying to separate exactly? The individual detail (mobile number) of each bill or each individual account ( account no.)? And by separate, do you mean a new html page? Does this report print to a web page or does your php script run at the command line? how is the billing data stored--queried from db and in 1-2 arrays?
pseudo-code:
$sql = "SELECT billing_name, acct_no FROM billing_table WHERE balance > 0";
$result = mysql_query ($query) or die ('SQL error'. mysql_error);
while ($billingUser= mysql_fetch_assoc($result)) {
// print bill heading
print "Billing Name: " . $billingUser['billing_name'];
print "Account No.: " . $billingUser['account_no'];
// get billing detail for current user we are looking at from WHILE LOOP
$detailSQL = "SELECT num_out_going_calls, sms_msgs
FROM billing_table
WHERE acct_no = $billingUser['acct_no']";
$detailResult = mysql_query ($detailSQL ) or die ('SQL error'. mysql_error);
while ($billingDetail = mysql_fetch_assoc($detailResult )) {
print "Num Outgoing Messages: " . $billingDetail['num_out_going_calls'];
print "Num SMS Messages: " . $billingDetail['sms_msgs'];
}
// print HTML page break
<p style="page-break-after: always">
}
Hope that helps,
bithead
Silmaril8n
06-20-2005, 01:02 PM
Why don't you just join the tables together in the first query?
bithead
06-20-2005, 01:22 PM
Why don't you just join the tables together in the first query?
You certainly could, but Chleng's problem was finding a way to break on the detail. A nested loop is a very simple solution to that problem (as I hope the code--didn't keep my indentation--illustrates).
Had you combined the queries you'd need a similar looping feature with a priming read and then check for change of accout no. to perform your break. I was shooting for the simpler of the two examples until I heard back from Chleng.
there is no spoon...
- bithead
vBulletin® v3.7.0, Copyright ©2000-2009, Jelsoft Enterprises Ltd.