Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Jul 2004
    Location
    engoku no anime
    Posts
    354
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Style sheet switch possible?

    Hello everybody. I recently started learning PHP, and I was simply wondering if there was a way to use PHP to "switch" style sheets for a page. Basically, it would look like any other page with a link to a printable version. The difference would be that I wouldn't create a completely new page, but simply "switch" style sheets from the screen version to a printable version. Is this possible?

    Thanks from a PHP newbie in advance!

  • #2
    Regular Coder dniwebdesign's Avatar
    Join Date
    Dec 2003
    Location
    Carrot River, Saskatchewan
    Posts
    841
    Thanks
    15
    Thanked 9 Times in 9 Posts
    sure... you can use something like below:

    PHP Code:
      $print=$_GET["print"];

      if(
    $print=="true")
      {
        echo 
    "<LINK rel=stylesheet type='text/css' href='css/printable.css'>";
      }
      else
      {
        echo 
    "<LINK rel=stylesheet type='text/css' href='css/normal.css'>";
      } 
    Say you have the URL... http://www.nsjhl.com/index.php
    To switch style sheets use http://www.nsjhl.com/index.php?print=true
    Dawson Irvine
    CEO - DNI Web Design
    http://www.dniwebdesign.com

  • #3
    Regular Coder
    Join Date
    Jul 2004
    Location
    engoku no anime
    Posts
    354
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks a lot! Going to test right now!

    // Edit

    Forgive me, but can you show me how I would apply that in a form? I can't seem to get it to work.

    Thank you again.

    // Edit

    I got it to work:

    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html lang="en-us">
    <head>
    <title>Testing!</title>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <?php
    $print
    =$_GET["print"];

      if(
    $print=="true")
      {
        echo 
    "<link rel='stylesheet' type='text/css' href='print.css'>";
      }
      else
      {
        echo 
    "<link rel='stylesheet' type='text/css' href='normal.css'>";
      }
    ?>
    </head>
    <body>
    <form action="test.php" method="GET">
      <input type="hidden" name="print" id="print" value="true">
      <input type="submit" value="Printable version">
    </form>
    <p>
    Hello!
    </p>
    </body>
    </html>
    Thank you so much! Now, to get it to work using <select> menus!
    Last edited by gohankid77; 09-25-2004 at 04:31 AM.

  • #4
    Regular Coder
    Join Date
    Jul 2004
    Location
    engoku no anime
    Posts
    354
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    <form action="test.php" method="GET">
      <select name="print">
        <option value="true">Printable version</option>
        <option value="false">Normal version</option>
      </select>
      <input type="submit" value="Go!">
    </form>
    That is the modified <select> code. Just so a user can select their own version! LOL

    Thank you, dniwebdesign!

  • #5
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    You don't need to do this ya know? You can do it with html

    Have both stylesheets linked up in your header like this

    <link rel="stylesheet" media="print" type="text/css" href="print.css">
    <link rel="stylesheet" type="text/css" href="normal.css">

  • #6
    Regular Coder
    Join Date
    Jul 2004
    Location
    engoku no anime
    Posts
    354
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yeah... I found out from another site I just wanted any users to see a printable version.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •