Re: [PHP] Accessing the 'media' attribute in php

2008-12-03 Thread Yeti
 I have enough trouble getting my rather ancient brain around PHP, and
 was hoping that I could avoid getting involved with JavaScript.
 However it seems that it, or CSS, are the only possibilities for this
 case.

If I understood you correctly what you want is to change the style of
the page when the user is printing it.
As others mentioned before all you would have to do would be adding a
second style sheet for that purpose.

EXAMPLE:
link rel=stylesheet media=screen href=/styles/main.css type=text/css /
link rel=stylesheet media=print href=/styles/print.css type=text/css /

That would be all. Now if you want the user to have some kind of
preview when clickin on a print the page button or link
you need either JavaScript or PHP. The easiest way I could think of
would be using the same print style sheet.

For JavaScript have a look at this page ...
http://www.quirksmode.org/dom/changess.html

I think it should work in most modern browsers. Still doing it with
PHP will work in every browser, but requires the page to reload ...
For PHP have a look at this page ...
http://www.maratz.com/blog/archives/2004/09/21/10-minutes-to-printer-friendly-page/#printQuery

//A yeti

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Accessing the 'media' attribute in php

2008-12-03 Thread Ashley Sheridan
On Wed, 2008-12-03 at 08:00 +0100, Maciek Sokolewicz wrote:
 Clancy wrote:
  Oh? 
  
  Unfortunately I have had great difficulty trying to find out how
  things really work, as all the books I have seen are recipe books,
  which tell you how to achieve particular results, but not what is
  going on behind the scenes.  I had assumed that when you hit the
  'print' button the browser sent a new request to the server, with a
  different set of parameters, but I gather from your reply that the
  browser issues the new (printer) page without reference to the server.
  Is this what actually happens?
  
  If so I fear I will have to work out how to achieve the results I want
  with CSS styles.  It would have been far simpler if I could have done
  it in php.
  
  Thank you for your help.
  
  On Wed, 3 Dec 2008 14:34:20 +1300, [EMAIL PROTECTED] (German Geek)
  wrote:
  
  PHP is a server side language...
 
  On Wed, Dec 3, 2008 at 2:16 PM, Clancy [EMAIL PROTECTED] wrote:
 
  Is it possible to access the 'media' attribute from php, so (for
  example) you can tailor a page for printing?
 
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 
 Rule #1 on this list: don't top post.
 
 That is how it works indeed, you request the page, the server runs the 
 php script, collects the output and sends it to the browser. You view 
 the page in the browser, press print, the browser sends the page data to 
 the printer spooler which sends it to the printer. No PHP involved after 
 it was sent from the server back to the browser. You basically have 2 
 options now:
 1. change the looks trough a different stylesheet (the pretty option)
 2. add a print button/link on your page which, when clicked, will 
 redirect to a new page in print format. Then use the javascript print 
 function to call up the browser's print dialog.
 
 As for books, most PHP books aren't recipe books, so you've been looking 
 at the wrong ones :) I can recommend O'Reilly's books, they're pretty 
 good. Especially Programming PHP [1]. But that's just my general liking 
 of those books ;)
 
 - Tul
 
 [1] http://oreilly.com/catalog/9780596006815/
 
Go with what Yeti said. The browser will automatically pick the right
stylesheet when the user presses the print button or you issue a
window.print() from Javascript. Whatever you do, don't have a separate
page for print view. This is one of those things that some bright
spark thought to do on a site at work, and the site in question was
already a couple hundred HTML pages, so he effectively doubled that
figure. It makes your work harder in the long run if you need to update
it at any time, and with the media=print attribute set for the extra
stylesheet, it's automatically selected anyways.

On an aside, Opera has a neat option that lets you select from all the
stylesheets a page has available, which will make it easier when you're
developing the stylesheet rather than having to keep clicking print
preview in your browser!


Ash
www.ashleysheridan.co.uk


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Accessing the 'media' attribute in php

2008-12-03 Thread Clancy
On Wed, 03 Dec 2008 08:15:14 +, [EMAIL PROTECTED] (Ashley
Sheridan) wrote:

Go with what Yeti said. The browser will automatically pick the right
stylesheet when the user presses the print button or you issue a
window.print() from Javascript. Whatever you do, don't have a separate
page for print view. This is one of those things that some bright
spark thought to do on a site at work, and the site in question was
already a couple hundred HTML pages, so he effectively doubled that
figure. It makes your work harder in the long run if you need to update
it at any time, and with the media=print attribute set for the extra
stylesheet, it's automatically selected anyways.

On an aside, Opera has a neat option that lets you select from all the
stylesheets a page has available, which will make it easier when you're
developing the stylesheet rather than having to keep clicking print
preview in your browser!

Thank you to everyone who has replied on this. While there are
reasonably good books on the individual tools (PHP, JavaScript, etc)
very few go into how they all interact, and this was the subject of my
confusion.  Maciek's succinct description has made it clear why my
original request could never be implemented, so I will have to use CSS
to achieve the results I want.

This is not THAT bad, but CSS was clearly not designed by a
programmer, and to my mind seems to have a very convoluted logic, so I
prefer to avoid using it if I can.

And thank you for the tip about Opera. That feature sounds as if it
could be very useful!

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Accessing the 'media' attribute in php

2008-12-03 Thread Michael Kubler

A couple of sites about making CSS print stylesheets.

http://www.alistapart.com/articles/goingtoprint/
http://www.webdesignschoolreview.com/css-printing.html

I'd send you links to more, but my Internet connection is shaped, and 
it's too slow to look through many more.


Michael Kubler
*G*rey *P*hoenix *P*roductions http://www.greyphoenix.biz



Clancy wrote:

On Wed, 3 Dec 2008 15:28:17 +1300, [EMAIL PROTECTED] (German Geek)
wrote:

  

You can do things on the client side with Javascript ;) Sorry, what was the
result you are after?



I have enough trouble getting my rather ancient brain around PHP, and
was hoping that I could avoid getting involved with JavaScript.
However it seems that it, or CSS, are the only possibilities for this
case.

Bother!


Re: [PHP] Accessing the 'media' attribute in php

2008-12-03 Thread ceo

 but I gather from your reply that the browser issues the new (printer)

 page without reference to the server.

 Is this what actually happens?



Yes, this is what actually happens for the browser print button.



You could do something like a Printer Friendly button to generate a PDF on 
the fly or somesuch, and POST back all the data you need to generate a nice PDF 
of the page.



Example:

http://l-i-e.com/resume.htm

(Source code link at the bottom of the page)



Reference material:

http://php.net/libpdf



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Accessing the 'media' attribute in php

2008-12-02 Thread German Geek
PHP is a server side language...

On Wed, Dec 3, 2008 at 2:16 PM, Clancy [EMAIL PROTECTED] wrote:

 Is it possible to access the 'media' attribute from php, so (for
 example) you can tailor a page for printing?


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




-- 
Tim-Hinnerk Heuer

http://www.ihostnz.com -- Web Design, Hosting and free Linux Support


Re: [PHP] Accessing the 'media' attribute in php

2008-12-02 Thread ceo

I think you just want to have a CSS sheet for print media and be done with it.



You could, in theory, add some kind of listener with JS, that would detect the 
'media' attribute and then Ajax back to the server to do something, but that's 
an awful Rube Goldberg compared to just one more tag with a print stylesheet.



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Accessing the 'media' attribute in php

2008-12-02 Thread Clancy
Oh? 

Unfortunately I have had great difficulty trying to find out how
things really work, as all the books I have seen are recipe books,
which tell you how to achieve particular results, but not what is
going on behind the scenes.  I had assumed that when you hit the
'print' button the browser sent a new request to the server, with a
different set of parameters, but I gather from your reply that the
browser issues the new (printer) page without reference to the server.
Is this what actually happens?

If so I fear I will have to work out how to achieve the results I want
with CSS styles.  It would have been far simpler if I could have done
it in php.

Thank you for your help.

On Wed, 3 Dec 2008 14:34:20 +1300, [EMAIL PROTECTED] (German Geek)
wrote:

PHP is a server side language...

On Wed, Dec 3, 2008 at 2:16 PM, Clancy [EMAIL PROTECTED] wrote:

 Is it possible to access the 'media' attribute from php, so (for
 example) you can tailor a page for printing?


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Accessing the 'media' attribute in php

2008-12-02 Thread German Geek
You can do things on the client side with Javascript ;) Sorry, what was the
result you are after?

On Wed, Dec 3, 2008 at 3:22 PM, Clancy [EMAIL PROTECTED] wrote:

 Oh?

 Unfortunately I have had great difficulty trying to find out how
 things really work, as all the books I have seen are recipe books,
 which tell you how to achieve particular results, but not what is
 going on behind the scenes.  I had assumed that when you hit the
 'print' button the browser sent a new request to the server, with a
 different set of parameters, but I gather from your reply that the
 browser issues the new (printer) page without reference to the server.
 Is this what actually happens?

 If so I fear I will have to work out how to achieve the results I want
 with CSS styles.  It would have been far simpler if I could have done
 it in php.

 Thank you for your help.

 On Wed, 3 Dec 2008 14:34:20 +1300, [EMAIL PROTECTED] (German Geek)
 wrote:

 PHP is a server side language...
 
 On Wed, Dec 3, 2008 at 2:16 PM, Clancy [EMAIL PROTECTED] wrote:
 
  Is it possible to access the 'media' attribute from php, so (for
  example) you can tailor a page for printing?
 
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




-- 
Tim-Hinnerk Heuer

http://www.ihostnz.com -- Web Design, Hosting and free Linux Support


Re: [PHP] Accessing the 'media' attribute in php

2008-12-02 Thread Maciek Sokolewicz

Clancy wrote:
Oh? 


Unfortunately I have had great difficulty trying to find out how
things really work, as all the books I have seen are recipe books,
which tell you how to achieve particular results, but not what is
going on behind the scenes.  I had assumed that when you hit the
'print' button the browser sent a new request to the server, with a
different set of parameters, but I gather from your reply that the
browser issues the new (printer) page without reference to the server.
Is this what actually happens?

If so I fear I will have to work out how to achieve the results I want
with CSS styles.  It would have been far simpler if I could have done
it in php.

Thank you for your help.

On Wed, 3 Dec 2008 14:34:20 +1300, [EMAIL PROTECTED] (German Geek)
wrote:


PHP is a server side language...

On Wed, Dec 3, 2008 at 2:16 PM, Clancy [EMAIL PROTECTED] wrote:


Is it possible to access the 'media' attribute from php, so (for
example) you can tailor a page for printing?


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Rule #1 on this list: don't top post.

That is how it works indeed, you request the page, the server runs the 
php script, collects the output and sends it to the browser. You view 
the page in the browser, press print, the browser sends the page data to 
the printer spooler which sends it to the printer. No PHP involved after 
it was sent from the server back to the browser. You basically have 2 
options now:

1. change the looks trough a different stylesheet (the pretty option)
2. add a print button/link on your page which, when clicked, will 
redirect to a new page in print format. Then use the javascript print 
function to call up the browser's print dialog.


As for books, most PHP books aren't recipe books, so you've been looking 
at the wrong ones :) I can recommend O'Reilly's books, they're pretty 
good. Especially Programming PHP [1]. But that's just my general liking 
of those books ;)


- Tul

[1] http://oreilly.com/catalog/9780596006815/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Accessing the 'media' attribute in php

2008-12-02 Thread Clancy
On Wed, 3 Dec 2008 15:28:17 +1300, [EMAIL PROTECTED] (German Geek)
wrote:

You can do things on the client side with Javascript ;) Sorry, what was the
result you are after?

I have enough trouble getting my rather ancient brain around PHP, and
was hoping that I could avoid getting involved with JavaScript.
However it seems that it, or CSS, are the only possibilities for this
case.

Bother!

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php