Page 1 of 1

Printing

Posted: Fri Jul 21, 2006 11:53 pm
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

Posted: Fri Jul 21, 2006 11:58 pm
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>';

Posted: Sat Jul 22, 2006 1:35 am
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]

Posted: Sat Jul 22, 2006 1:44 am
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.

Posted: Sat Jul 22, 2006 1:48 am
by shiranwas
what i want to get is a hard copy of the table appearing on the page

Posted: Sat Jul 22, 2006 1:53 am
by Benjamin
When your viewing the page, click on File->Print->OK

Posted: Sat Jul 22, 2006 1:58 am
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

Posted: Sat Jul 22, 2006 2:05 am
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?

Posted: Sat Jul 22, 2006 2:17 am
by shiranwas
guru,,

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

THANX AGAIN

Just a little sample

Posted: Sun Jul 23, 2006 8:21 am
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: