perleager has asked for the wisdom of the Perl Monks concerning the following question:

Hello

I have a code where it prints out a list of 1000+ results from a mysql database. (select sessions from data_sessions) Keep in mind that I would need ALL of these results printed daily. (basically I goto the script which displays all 1000+ results, then click print from browser)

Since sometimes it can return more then 1000 results, I'm interested in splitting them up, 100 per page.

As of now the program displays ALL results onto one page, that way I can just print from browser and have all the results printed.

Now my questions is if I were to split up the results 100 per page, then is there anyway I can have a "Print All Pages" link / feature that is able to print all 100 results? That way I do not have to go through each single page and click print. If not then I don't think its worth me ediiting my code around due to the inconvenience it will bring me.

Thank you,

perleager

Replies are listed 'Best First'.
Re: Printing out all pages
by injunjoel (Priest) on Jan 01, 2005 at 23:07 UTC
    Greetings all,
    Though I'm not sure I fully understand your request I'll take a stab at it.
    You are re-working your results into 100 results per page chunks and you want to print all of the results to individual pages 100 at a time right?
    Since you mentioned the browser I am assuming you are using HTML in which case you can easily do this with CSS2 if you are using IE 4.0+. The print properties page-break-after and page-break-before are what you need to use to split up your printed pages. I have used these on other projects and they worked great for the client. Here is a link to the w3schools tutorial on CSS2 print properties.
    So now you can print out your 100 results and throw in the CSS tag. Here is an example:
    #In the head of your HTML output <style type="text/css"> .pg_break {page-break-after: always} </style> #later in the page #... your 100 results <br class="pg_break"> #... more results 100 at a time <br class="pg_break"> # and on and on until you've got all your results.

    Again this is currently only supported in IE 4.0+
    Hope that helps,

    -InjunJoel
    "I do not feel obliged to believe that the same God who endowed us with sense, reason and intellect has intended us to forego their use." -Galileo
Re: Printing out all pages
by ww (Archbishop) on Jan 01, 2005 at 23:10 UTC
    • Start with your existing code to print all to a single page.
    • assign whatever your're using as its name to a new variable such as $all
    • add code to break the whole (hash? array? whatever) into 100-items pages (I infer from your description that you want it printed to .htm) in the (added) pagination part of the script
    • code an html link <a href="$all">$all</a> (OR "Print as single page</a>" OR whatever floats your boat) into the output side of the pagination section
    • you may want to put the link just after <body> and again, just before </body> for user convenience...

    ...or am I missing something?

    <G> What size type are you using that 100 items ( ??lines?? ) fit on a single page?
Re: Printing out all pages
by fuzzyping (Chaplain) on Jan 01, 2005 at 22:55 UTC
    It sounds to me like you're adding unnecessary complexity to the problem. If you want to print out all of the sessions, why not simply print them out via pipe to lpr? Why bother trying to prepare them for your browser, when the end effect is the same?

    What I'm really getting at is to avoid introducing your browser into the scenario at all. If you want to print them out, then just write a short function/method (or new script) to query the db and format/print out the results.

    As far as viewing 100 rows per browser view, you want to integrate some sort of pager functionality. This can be done quite easily by crafting your sql query to increment each time.

    Hope this helps,

    -fp
      Thank you all for replying-

      Lets say my first feature, which prints out all 1000 results onto a single HTML page. Now If I click print from the browser, it'll Automatically print all 1000 results broken up into pages (As of now its not 100 per page).

      Now what I want to do is to edit my perl coding so it Displays out 100 results per page. But IF I do it this way , then I can't just click print from the browser and have ALL 1000 results printed, instead it will only print the results displayed on that Current Page (100 results will be displayed).

      So my question is there anyway to make a "PRINT ALL RESULTS FROM ALL PAGES" feature? I think ifuzzyping\i came closest to understanding my question since he mentioned a function to query the db and format/print results.

      Thank you,
      Perleager
Re: Printing out all pages
by chromatic (Archbishop) on Jan 01, 2005 at 23:11 UTC

    I don't understand the question.

    You already have this feature working. If you add another feature, why would the first stop working?