Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 4 of 4
  1. #1
    Junior Member
    Join Date
    Feb 2003
    Posts
    15
    Member #
    609
    hello everybody,

    I would like to know if theres a way to generate reports using a template.
    Say, for example i design a template using a notepad.All the fields representing in this template are the columns of my table.
    So when ever i want to print a report, i would like to call this template and print each record in a separate page.
    I think it would be fine if the final document which will be printed as a pdf file.
    Could somebody guide me in the right way.

    Thanks a lot

  2.  

  3. #2
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    Ok, well reports can be kind of complex... but I'm assuming that the text file that you have is a mono-spaced type-face?

    You can do something in HTML using <pre> tags and CSS to put a page break at the end of each page (for printing purposes).

    Probably the best way to do this, though, would be to follow the Crystal.NET DHTML reporting templates and use <div> elements to place your items absolutely on each page. that way, you can restrict the overflow of each element (style="overflow:hidden") to ensure that everything formats correctly.

    If you want to do it with PHP, you can simply make your template with the appropriate HTML and loop through each record in your MySQL result, replacing the template page with the values from the database and appending the result to an output file.

    Once you're done creating the output file, you can then print it to the screen or make it available for download... etc.

    Here's what I'm thinking...

    template.htm:
    Code:
            <p>Page ?PAGE?</p>
            <table style="page-break-after: always" width="100%" 
                cellpadding="0" cellspacing="0" border="1">
                <tr>
                    <th>Name</th>
                    <td>?NAME?</td>
                </tr>
                <tr>
                    <th>Address</th>
                    <td>?ADDRESS?</td>
                </tr>
                <tr>
                    <th>Phone</th>
                    <td>?PHONE?</td>
                </tr>
            </table>
    The tokens in each record that are going to be replaced are in the format ?COLUMN_NAME? corresponding to the columns in your database.

    Here's what you would do for your php:

    displayReport.php:
    PHP Code:
    <?php
    // get the contents of template.htm 
    // into the variable $template

    // get a resultset from your database

    echo "<html><body>";

    $this_page "";
    $i 0;
    while (
    $row mysql_fetch_array($resultMYSQL_ASSOC) {
        
    $i++;
        
    $this_page $template;
        
    $this_page str_replace($this_page"?PAGE?"$i);
        
    $this_page str_replace($this_page"?NAME?"$row["name"]);
        
    $this_page str_replace($this_page"?ADDRESS?"$row["address"]);
        
    $this_page str_replace($this_page"?PHONE?"$row["phone"]);
        echo 
    $this_page;
    }

    echo 
    "</body></html>";
    ?>
    That should do the basics, outputting the report to the screen.

  4. #3
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    When you want to get more complex, you can create templates for report headers, page headers, group headers, sections, group footers, page footers, and report footers.... assembling them all together to make one file. It takes a little more thought, but results in a much more fine-tuned final product

  5. #4
    Junior Member
    Join Date
    Feb 2003
    Posts
    15
    Member #
    609
    Thank you very much transio.I'll go give a try.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 10:23 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com