/    Sign up×
Community /Pin to ProfileBookmark

help w/agebreak

Hi, I’m trying to print this doc with heading at top of each printed page,
page# at bottom of each page, thousands “,” at “totdue” and without the
filename on each page. any help? Thanks
Following is my current code

[CODE]<html><head>
<style>
@page { size 8.5in 11in; margin: 2cm }
div.page { page-break-after: always }
</style>
</head><body><center>
<div class=”page”>
<?php
error_reporting(0);
mysql_connect(‘localhost’,’root’,’xxxxx’);
mysql_select_db(‘homedb’) or die(“Unable to select database”);
$query=” SELECT * FROM oocust WHERE payrec = ‘R’ AND pd = ‘N’ ORDER BY datepaid ASC”;
$result=mysql_query($query);
$num=mysql_numrows($result);

echo date(‘m/d/y’);
echo “<font size=+1><b><center> Accounts Receivable Report</font></center></b></b><br />”;
?>
<table cellspacing=0 cellpadding=2 border=1>
<thead>
<tr>
<th colspan=4></th>
<th bgcolor=”#ccffff”>date</th>
<th bgcolor=”#ccffff”>days</th>
<th bgcolor=”#ccffff”>amt</th>
<tr>
<th bgcolor=”#ccffff”>recur?</th>
<th bgcolor=”#ccffff”>acct#</th>
<th bgcolor=”#ccffff”>creditor</th>
<th bgcolor=”#ccffff”>purpose</th>
<th bgcolor=”#ccffff”>due</th>
<th bgcolor=”#ccffff”>late</th>
<th bgcolor=”#ccffff”>due</th>
</tr>
<?php
while($row = mysql_fetch_array($result))
{
$totdue += $row[‘amtdue’];
echo ‘
<tr>
<td>’, $row[‘status’], ‘</td>
<td>’, $row[‘acctno’], ‘</td>
<td>’, $row[‘bname’], ‘</td>
<td>’, $row[‘purpose’], ‘</td>
<td>’, $row[‘duedate’], ‘</td>
<td align=right class=”currency”>’, ($late > 120 ? ‘pastdue’ : $row[‘dayslate’]), ‘</td>

<td align=right class=”currency”>$’.number_format($row[‘amtdue’],2).'</td> // ****perfect****

</tr>’;
}
echo ‘
<tr>
<th bgcolor=”#ccffff” scope=”row” colspan=”6″>Grand Total:</th>
// <td bgcolor=”#FFD4D4″ class=”currency”>$’, number_format($totdue, 2, ‘.’, ”), ‘</td>

<td align=right class=”currency”>$’. number_format(‘$totdue’,2).'</td> // no thousands “,” ***

</tr>
</table>’;
echo “Page 1″;
?>
</div>
<div class=”page”>
<?php
echo “Page 2”;

mysql_close();
?>
</body></html>[/CODE]

to post a comment
PHP

8 Comments(s)

Copy linkTweet thisAlerts:
@deathshadowMay 20.2014 — Is this homework or something? This is like the seventh time on three different forums in two weeks I've seen basically this same buggy, broken, garbage 1997 train wreck of code.

Some tips:

1) quotes aren't optional on attributes after 1997

2) attributes like bgcolor and tags like CENTER and FONT have no business on websites written after 1997.

3) this is 2014 not 2004, you shouldn't be using mysql_ functions either, hence the [url=http://us3.php.net/function.mysql-connect]giant red warning boxes[/url] in the manual?

4) You seem to know THEAD, have you ever heard of TFOOT? Guess what it does. You also aren't declaring a TBODY, so your THEAD isn't doing jack ****.

5) pagination is handled client-side, the ONLY place you'd be able to set that is using CSS with generated content; even Javascript can't say what page is being printed.

6) There are other tags and attributes you should be using like CAPTION and SCOPE.

7) you want headings split, split them with breaks and not as separate elements, that's semantic gibberish.

8) instead of targeting page for dimensions, you should just let the page do what it does -- why? because you don't know what size paper the user it printing to!

9) turning off error reporting is BAD, no, REALLY BAD... As in "are you nuts?" BAD.

Now, because TFOOT has to go before THEAD, we have to buffer the output of the rows as we add them up -- or we run a separate query for the total. Laughably, the second query might be faster.

&lt;?php

echo '
&lt;table id="accountsReceivable"&gt;
&lt;caption&gt;Accounts Receivable Report - ', date('m/d/y'), '&lt;/caption&gt;
&lt;thead&gt;
&lt;tr&gt; <br/>
&lt;th scope="col"&gt;recur?&lt;/th&gt;
&lt;th scope="col"&gt;acct#&lt;/th&gt;
&lt;th scope="col"&gt;creditor&lt;/th&gt;
&lt;th scope="col"&gt;purpose&lt;/th&gt;
&lt;th scope="col"&gt;date&lt;br /&gt;due&lt;/th&gt;
&lt;th scope="col"&gt;days&lt;br /&gt;late&lt;/th&gt;
&lt;th scope="col"&gt;amt&lt;br /&gt;due&lt;/th&gt;
&lt;tr&gt;
&lt;/thead&gt;&lt;tfoot&gt;
&lt;tr&gt;
&lt;td colspan="7"&gt;
Page:
&lt;span class="pages"&gt;&lt;/span&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tfoot&gt;&lt;tbody&gt;
';

$db = new PDO(
'mysql:host=localhost;dbname=homedb',
'root', // username
'xxxxx' // password
);

$statement = $db-&gt;query('
SELECT * FROM oocust
WHERE payrec = 'R'
AND pd = 'N'
ORDER BY datepaid ASC
');

while ($row = $statement-&gt;fetch()) {
echo '&lt;tr&gt;
&lt;td&gt;', $row['status'], '&lt;/td&gt;
&lt;td&gt;', $row['acctno'], '&lt;/td&gt;
&lt;td&gt;', $row['bname'], '&lt;/td&gt;
&lt;td&gt;', $row['purpose'], '&lt;/td&gt;
&lt;td&gt;', $row['duedate'], '&lt;/td&gt; <br/>
&lt;td&gt;', (
$row['dayslate'] &gt; 120 ? 'Past Due' : $row['dayslate']
), '&lt;/td&gt;
&lt;td class="currency"&gt;
', number_format($row['amtdue'], 2), '
&lt;/td&gt;
&lt;/tr&gt;';
$totdue += $row['amtdue']; <br/>
}

echo '&lt;tr class="grandTotal"&gt;
&lt;th scope="row" colspan="6"&gt;Grand Total (USD):&lt;/th&gt;
&lt;td class="currency"&gt;
$', number_format($totdue, 2), '
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;';

?&gt;


As to showing the page numbers, that takes a bit of CSS that... gimme a sec.

body {
counter-reset: page;
}

#accountsReceivable .pages:before {
counter-increment: page;
content: counter(page);
}
Copy linkTweet thisAlerts:
@12StringsauthorMay 21.2014 — Hi Dead Shade, I must say here that I really stand in awe of your coding knowledge.

I compare you (positively) , your demenour and expertise to "House", you know, the TV

show. The reason being, I consider you among the best and if you were a doc

I would look to you. Sticks and stones...

Notice: Undefined variable: totdue in C:xampphtdocsinvoiceap_report.php on line 49

1) use the CODE tags on the forum, it might help us make sense of your code logic.

I didn't intend to bypass the CODE tags - old age = little (no) memory.

2) CSS exists for a reason, use it. This is 2014 not 1997, even in testing you shouldn't

be trying to use BGCOLOR or ALIGN. Likewise targeting via CSS means you should have

one markup for ALL your media targets, so that 'print' class and DIV for nothing around

the table doesn't make much sense.

If I were coding for public use I would definitely not be using the attributes that I
enjoy but this is LOCAL and my pastime and I enjoy seeing what I can get away with.


3) Semantics exist for a reason, that DIV at the top should be either a H1 or H2 before

the table -- or even more semantically a CAPTION inside the table.

yeah, as I encounter these issues I try for documentation - The PHP manual is difficult -
like you already know so they're kinda reminding, otherwise, where's the need for forums?


4) the lack of sensible formatting (which I was able to get from the forum's quote feature),

string additions for no reason, and opening/closing of PHP for no good reason is most

likely a hefty part of what's biting you on that code... Especially even using that garbage

"endforeach" nonsense.

That"endforeach" nonsense was suggested by a forum moderator. Looking at the PHP site,
I read "endoreach does not exist"



5) you can't add classes on the CLOSING tag of an element. </table class="print"> is

gibberish. Classes go when you OPEN it, not when you close it.

Again, if not for you (caustic remarks and all), I would not be aware of this

6) You are opening THEAD more than once...

My bad

7) you aren't closing your TR

Again, inattention on my part

8) your THEAD content seems to have nothing to do with the values being displayed...

9) You're declaring THEAD, where's your matching TBODY?

10) Most of what you are trying to do is THEAD and TFOOT's job, with CSS 2.1's assistance.

8,9 & 10 - I'm reading up on now

11) Even in testing, get a PROPER head and doctype on it, as browsers (even so called compliant ones) can behave differently without them! It shouldn't be a headache to copy/paste a standard document start on there.

I thank you

12) Beware that even though we theoretically have print.css -- both Firefuxxors and Interdebt

Exploder apply their own styling over it and seem to for some jacktarded reason think your

screen.css should still be applied. You can optionally turn that behavior off as a user,

but not as the developer. ?

I'm not sure about your last line
Copy linkTweet thisAlerts:
@deathshadowMay 22.2014 — I didn't intend to bypass the CODE tags - old age = little (no) memory.[/quote]
No problem, with this parkinsonism I'm not too far behind you ?

... and yeah, you have to define $totdue first, add $totdue = 0; before the "while".

If I were coding for public use I would definitely not be using the attributes that I

enjoy but this is LOCAL and my pastime and I enjoy seeing what I can get away with.[/quote]

Strange as it sounds, it's actually easier not to declare them over and over like that. Since it's in your THEAD You can say it once in your CSS instead of many times in the markup -- one big tip; find a editor that lets you run multiple windows instead of tabs, so you can put your markup side-by-side with your stylesheet. Since on todays widescreens you have plenty of horizontal space, having the markup on one side and CSS on the other is a lot easier than scrolling up and down in the same file, or writing the same thing over and over again in the markup.

It also helps establish the good practice of NEVER saying what things look like in the markup.

That"endforeach" nonsense was suggested by a forum moderator. Looking at the PHP site, I read "endoreach does not exist"[/quote]
There's a lot of outdated/outmoded advice out there - it makes things hard for those starting out or just doing things casually when there are decade and a half out of date practices still being taught or promoted. More so in PHP as the latest versions are getting rid of a LOT of the outdated/broken methodologies. See PDO/mySQLi vs. the old mysql_ functions -- 90%+ of the code people are still writing uses mysql_connect and it's kin, when we've been told for eight years to stop doing so and for just over two years there's been [url=http://us3.php.net/function.mysql-connect]giant red warning boxes[/url] that they're going away and WILL STOP WORKING soon; yet the majority of people writing tutorials, books and new sites are dragging their heels; sad when the old functions are ridiculously vulnerable not just from a sanitation of input standpoint, but also in terms of scope.

As such, it's very easy to get bad advice as most people are still stuck in the past and not updating their skillsets.

8,9 & 10 - I'm reading up on now[/quote]
If you want a decent 'plain english' explanation of HTML tags, I suggest this older reference -- it's spot on:

http://htmlhelp.com/reference/html40/

But to break it down quick:

[b]THEAD[/b] wraps sets of TR you want printed at the start of every table, and at the top of every page when a table is interrupted by a page-break. Typically a THEAD's single TR (you can have more than one, but it rarely makes sense) contains TH.

[b]TFOOT[/b] is THEAD's counterpart -- it prints at the end of the table, and at the bottom of every page when a table is interrupted by a page-break.

[b]TBODY[/b] is your actual data rows.

There's also that SCOPE attribute I used -- should be pretty clear what it does, it declares if the heading cell is for the row or the column.

It's actually funny, I'd guesstimate (pulling a number out my backside based on experience) that 90% or more developers still are unaware there are even tags other than TR and TD that go in a table.

I'm not sure about your last line[/QUOTE]
By default IE and FF both override your print.css with their own settings and play mix-match with values from the screen.css -- it's one of the reasons (along with handhelds pulling similar games) that media targets (the values for the MEDIA attribute on LINK) were semi-undeployable. The problem wasn't the specification, it was the two main browsers during the first decade of HTML 4 basically ignoring that there even was a specification.

Laughably, FF still has massive gaps in how it handles HTML 4 -- which of course is why they're implementing HTML 5 garbage first. :/
Copy linkTweet thisAlerts:
@12StringsauthorMay 22.2014 — thanks a lot , u mentioned a text editor to use multiple windows. how about pointing to one?
Copy linkTweet thisAlerts:
@deathshadowMay 22.2014 — Well the one I use is called "Flo's Notepad 2

http://www.flos-freeware.ch/notepad2.html

It's based on Scintilla (while not being a total piece of Scite) so it has pretty much every feature you'd expect a programmers editor to have, but without the massive step backwards in functionality that is shoving all the editor boxes into a single window. I like it because it also lets me turn off all the garbage that annoys me -- like auto-closing markup, colour syntax highlighting, and all that other crap that just makes coding HARDER... while still providing useful things like line-wrap indicators, line-wrap indenting, changing the default tab size, long line guide, and the typical plethora of search, brace matching, replace and 'block conversion' functions, single file instances (so you don't accidentally open a new copy of the same file).

Actually finding editors that aren't tabbed and shove everything into one window is kind-of hard. Even the ones that let you 'detach' a tab (like classic Opera's MDI used to let you) don't use open in a new window as the default behavior; the list gets pretty short. Flo's, Win32pad... and... regular plain-jane notepad. I can't even think of any others that allow for it.

Really Flo's Notepad2 is the best programming editor I've ever used -- and I've tried a LOT of them the past three and a half decades... I say it's the best BECAUSE it doesn't load up on features I'm never going to use or just get in my blasted way. I say it's the best because honestly, I can't fathom a legitimate reason for them to ever issue a new version other than if it breaks in a new version of Windows.

Some things should be simple enough -- like text editors -- you shouldn't need a new version every fifteen minutes.
Copy linkTweet thisAlerts:
@12StringsauthorMay 23.2014 — are u referring 2 notepade++? I discovered it some time ago and use it 2 keep track of line#s.
Copy linkTweet thisAlerts:
@NogDogMay 23.2014 — Choosing the "best" code editor is like choosing the "best" programming language or the "best" framework: get 20 random developers in a room, and you'll have approximately 19 suggestions for each. ?

I've been on Komodo Edit for a couple years now, but who knows what I'll be using in another year? (And sometimes, when I'm in a hurry and I'm on a Linux VM, I just type [FONT=Courier New][B]vi filename.php[/B][/FONT] . ? )
Copy linkTweet thisAlerts:
@deathshadowMay 23.2014 — are u referring 2 notepade++? I discovered it some time ago and use it 2 keep track of line#s.[/QUOTE]
No, I linked to what I'm referring to. "Flo's Notepad 2" -- AGAIN:

http://www.flos-freeware.ch/notepad2.html

Notepad++ is a fine program, but it's inability to default to non-tabbed editing, painfully slow (to me) loading time, and endless bloated nonsense I'd never actually use when writing code; much less the massive amount of stuff I'd have to turn off before even STARTING to use it, is why I rejected it. People who need the crutches and training wheels seem to like it though. I think I really gave up on it when I couldn't figure out how to get rid of the idiotic space wasting tab interface and toolbar garbage... but I'm wierd, the only things I want to see is a status bar at the bottom, filename as the window frame title, and a old-fashioned text menu. Like I'm supposed to know what all those crappy little icons are even supposed to mean? Much less if you're set to single instance, what the **** does it need a tab bar for?

Choosing the "best" code editor is like choosing the "best" programming language or the "best" framework: get 20 random developers in a room, and you'll have approximately 19 suggestions for each. ?[/quote]
True enough -- otherwise we wouldn't have dozens if not hundreds of different ones to choose from. Things that piss me off -- like autocomplete, autoclosures, space wasting 'false simplicity' toolbars, the illegible acid trip known as colour syntax highlighting, tabs - might be the bee's knees to someone else.

See the people who find vi/vim or emacs to be 'the best', while I sit here wondering just what the **** they are smoking.

I've been on Komodo Edit for a couple years now[/QUOTE]
To me the 70 megabyte download was a warning it would be a giant steaming pile I wouldn't want to use; but it's more of an IDE, which to me is just a waste of time and effort, and usually eats up screen real-estate with crap I don't want or need.

Once installed the ridiculously long startup time, oddball toolbar enabling/disabling that is near impossible to restore should you accidentally turn off the 'normal' menu, goofy "overview" thing on the side I could never figure out how to disable, even goofier "start page" and stupid "project management" crap, etc, etc... is exactly what I mean by garbage that just gets in the way of *SHOCK* sitting down and just writing some code.

Of course that it forces EVERYTHING into a single window without the means to detach the tabs or run as single instances makes it useless to me as a multiple display user... or even on a widescreen. It's a poster child for everything wrong (IMHO) with so called "IDE's".

Me? I just want to *SHOCK* open a bloody window and edit some plaintext. IDE's and some of the fancier plain editors have all this extra garbage that just gets in the way of that... which is why I use a basic notepad replacement regardless of if I'm writing Pascal, C, assembler, PHP, JS, HTML or CSS. If you need anything more, you probably don't have the skills to be writing code in the first place.

Hell, if Notepad had proper character set conversion capabilities, tab/space conversions, and regex for search/replace -- I'd probably still be using plain-Jane notepad.
×

Success!

Help @12Strings spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...