Printing

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
shiranwas
Forum Commoner
Posts: 53
Joined: Fri Jul 07, 2006 10:41 pm
Location: Colombo

Printing

Post by shiranwas »

Hi,

can anyone tell me how to get print out of
a table which consist of data retrived from a table.

(PHP Codings)

thanx in advance


shiran
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Here is a quick and dirty example..

Code: Select all

$resource = mysql_query($query);

echo '<table>';

while ($data = mysql_fetch_assoc($resource)) {
    echo '<tr><td>' . $data['fieldName'] . '</td></tr>';
}

echo '</table>';
User avatar
shiranwas
Forum Commoner
Posts: 53
Joined: Fri Jul 07, 2006 10:41 pm
Location: Colombo

Post by shiranwas »

Weirdan | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


guru,

I have done what u sent, what i want is to get a print out of the table appeared after i i do this
coding

Code: Select all

$resource = mysql_query($query); 

echo '<table>'; 

while ($data = mysql_fetch_assoc($resource)) { 
    echo '<tr><td>' . $data['fieldName'] . '</td></tr>'; 
} 

echo '</table>';


Thanx


Weirdan | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Are you saying you want it to look different when it's printed? You can assign a different css style sheet for printed web pages. I'm not sure I understand what you are asking.
User avatar
shiranwas
Forum Commoner
Posts: 53
Joined: Fri Jul 07, 2006 10:41 pm
Location: Colombo

Post by shiranwas »

what i want to get is a hard copy of the table appearing on the page
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

When your viewing the page, click on File->Print->OK
User avatar
shiranwas
Forum Commoner
Posts: 53
Joined: Fri Jul 07, 2006 10:41 pm
Location: Colombo

Post by shiranwas »

actually dat not i ment, i want to get a proper print out which should look like
a report with headers and etc.. thanx



if i put it another way how to create reports with php
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Well this is really a client side issue, not a PHP issue.

Basically you want to set the margin's to 0 as the printer will set those automatically. Set the width to AUTO so that it fit's ok on the page. There are some CSS attributes you can use to specify page breaks. Without doing research I'm not sure if you can specify headers and footers..

PHP does not have the ability to control what is sent to the printer. Maybe you could look into converting it into a PDF?
User avatar
shiranwas
Forum Commoner
Posts: 53
Joined: Fri Jul 07, 2006 10:41 pm
Location: Colombo

Post by shiranwas »

guru,,

thanx for the help, ihope i can get this done using CSS.

THANX AGAIN
User avatar
ronverdonk
Forum Commoner
Posts: 34
Joined: Sat Jun 10, 2006 7:06 am
Location: Netherlands

Just a little sample

Post by ronverdonk »

Sounds like you can use a little sample. Well, here it is:

A form with heading3 and 4 and a 1-line table. It will all display on the screen, but when I print it, I want h3 to print and h4 not. Of the table I want the 2nd column to print and the first one not.

By including a CSS stylesheet with the media=print option, I can handle this. Just define a class "nopr" with
"display:none" and everything on your form with class=nopr will not print.

Code: Select all

The PHP code
<?php
echo '<link rel="stylesheet" media="print" type="text/css" href="prtit.css" />';
echo '<h3 class="prt">I want this to be printed</h3>';
echo '<h4 class="nopr">This one will not print</h4>';
echo '<table border="0">';
echo '<th class="nopr">Amount</th><th class="prt">Description</th>';
echo '<tr><td class="nopr">100</td><td class="prt">Whatever</td></tr>';
echo '</table>';
?>
The CSS (prtit.css):
.nopr {display:none;}
.prt {font-family:verdana,sans-serif; color:#000000;}
You can apply this method to your table.

Ronald :cool:
Post Reply