activating alternative style sheet with php

Discussion in 'HTML' started by picayunish, Oct 17, 2003.

  1. picayunish

    picayunish Guest

    G'dag,

    I'm trying to activate an alternative style sheet by clicking on a
    hyperlink.
    The problem what I have is when clicking on the link, the page jumps to the
    right chapter but it wouldn't activate the alternative style sheet.

    The code is:
    <head>
    <link rel="stylesheet" type="text/css" title="basic page style"
    href="style.css">
    <?php
    if ($style="vert1") {echo '<link rel="stylesheet" type="text/css"
    title="vertical" href="vert.css">' ."\n";}
    ?>
    </head>
    <body>
    <a <?php $style="vert1"; ?> href="#vert1">jgjglkgfd dkgjlkd</a>

    some content
    <h2><a name="vert1"></a>blah</h2>
    more content
    </body>

    This is the experimental site:
    http://www.semi-conductor.nl/test/

    What am I doing wrong?
    --
    Edwin van der Vaart
    http://www.semi-conductor.nl/ Links to Semiconductors sites
    http://members.chello.nl/e.vandervaart/ Experimental site
     
    picayunish, Oct 17, 2003
    #1
    1. Advertising

  2. picayunish wrote:

    > What am I doing wrong?


    Ummm... PHP doesn't work like that. Here is a basic stylesheet switcher
    for you. It assumes that you have a directory "styles" containing
    "black.css", "white.css" and "red.css".

    ============================ example.php =============================
    <!DOCTYPE whatever>
    <html>
    <head>
    <title>Example</title>
    <link rel="stylesheet" type="text/css" media="screen,projection"
    <?php echo ' href="styles/' . $_GET['style'] . '.css"'; ?> >
    </head>
    <body>
    <h1>Example</h1>
    <p>The style you chose was <code><?php echo $_GET['style']; ?>.css</code>.</p>
    <ul>
    <li><a href="example.org?style=red">Red</a></li>
    <li><a href="example.org?style=white">White</a></li>
    <li><a href="example.org?style=black">Black</a></li>
    </ul>
    </body>
    </html>
    ======================================================================

    In short, if you want a user to interact with a PHP script, it has to be
    with clicking links to reload the page, tagging on parameters at the end
    of the URL; or via form submits.

    One improvement to the above script would be to add a default stylesheet.

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me - http://www.goddamn.co.uk/tobyink/?id=132
     
    Toby A Inkster, Oct 17, 2003
    #2
    1. Advertising

  3. picayunish

    picayunish Guest

    Toby A Inkster wrote in news:p:
    > picayunish wrote:
    >
    >> What am I doing wrong?

    >
    > Ummm... PHP doesn't work like that. Here is a basic stylesheet switcher
    > for you. It assumes that you have a directory "styles" containing
    > "black.css", "white.css" and "red.css".
    >
    > ============================ example.php =============================
    > <!DOCTYPE whatever>
    > <html>
    > <head>
    > <title>Example</title>
    > <link rel="stylesheet" type="text/css" media="screen,projection"
    > <?php echo ' href="styles/' . $_GET['style'] . '.css"'; ?> >
    > </head>
    > <body>
    > <h1>Example</h1>
    > <p>The style you chose was <code><?php echo $_GET['style'];
    > ?>.css</code>.</p> <ul>
    > <li><a href="example.org?style=red">Red</a></li>
    > <li><a href="example.org?style=white">White</a></li>
    > <li><a href="example.org?style=black">Black</a></li>
    > </ul>
    > </body>
    > </html>
    > ======================================================================
    >
    > In short, if you want a user to interact with a PHP script, it has to be
    > with clicking links to reload the page, tagging on parameters at the end
    > of the URL; or via form submits.
    >
    > One improvement to the above script would be to add a default stylesheet.


    Thanx Toby.
    It's getting late. I'll try it later of the day, so good night.
    --
    Edwin van der Vaart
    http://www.semi-conductor.nl/ Links to Semiconductors sites
    http://members.chello.nl/e.vandervaart/ Experimental site
     
    picayunish, Oct 18, 2003
    #3
  4. picayunish

    brucie Guest

    brucie, Oct 18, 2003
    #4
  5. picayunish

    picayunish Guest

    picayunish, Oct 19, 2003
    #5
  6. picayunish

    picayunish Guest

    Toby A Inkster wrote in news:p:
    > picayunish wrote:
    >
    >> What am I doing wrong?

    >
    > Ummm... PHP doesn't work like that. Here is a basic stylesheet switcher
    > for you. It assumes that you have a directory "styles" containing
    > "black.css", "white.css" and "red.css".
    >
    > ============================ begin example.php

    =============================

    [snip]

    > ============================ end example.php

    ==============================
    >
    > In short, if you want a user to interact with a PHP script, it has to be
    > with clicking links to reload the page, tagging on parameters at the end
    > of the URL; or via form submits.
    >
    > One improvement to the above script would be to add a default stylesheet.


    Dunno, it works great.
    --
    Edwin van der Vaart
    http://www.semi-conductor.nl/ Links to Semiconductors sites
    http://members.chello.nl/e.vandervaart/ Experimental site
     
    picayunish, Oct 19, 2003
    #6
  7. picayunish

    Fabian Guest

    Toby A Inkster wrote:
    > One improvement to the above script would be to add a default
    > stylesheet.


    And how should you do that? With an if then else structure? Cause I like the
    script, it's easy. I've once made one with an if then else to see if the
    variable was filled but this one is easier (though it hasn't got a default
    style).


    --
    Fabian
    http://givelove.be/
     
    Fabian, Oct 19, 2003
    #7
  8. Fabian wrote:

    > Toby A Inkster wrote:
    >> One improvement to the above script would be to add a default
    >> stylesheet.

    >
    > And how should you do that? With an if then else structure?


    Well, I *was* going to leave it as an exercise to the reader, but since
    you asked:

    ============================ example.php =============================
    <!DOCTYPE whatever>
    <?php
    $s = $_GET['style'];
    if (!($s)) { $s = 'red'; }
    ?>
    <html>
    <head>
    <title>Example</title>
    <link rel="stylesheet" type="text/css" media="screen,projection"
    <?php echo ' href="styles/' . $s . '.css"'; ?> >
    </head>
    <body>
    <h1>Example</h1>
    <p>The style you chose was <code><?php echo $s ?>.css</code>.</p>
    <ul>
    <li><a href="example.org?style=red">Red</a></li>
    <li><a href="example.org?style=white">White</a></li>
    <li><a href="example.org?style=black">Black</a></li>
    </ul>
    </body>
    </html>
    ======================================================================


    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me - http://www.goddamn.co.uk/tobyink/?id=132
     
    Toby A Inkster, Oct 19, 2003
    #8
  9. picayunish

    Wipkip Guest

    Toby A Inkster wrote:
    > Fabian wrote:
    >
    >> Toby A Inkster wrote:
    >>> One improvement to the above script would be to add a default
    >>> stylesheet.

    >>
    >> And how should you do that? With an if then else structure?

    >
    > Well, I *was* going to leave it as an exercise to the reader, but
    > since you asked:
    >

    Toby, please don't assume that all of us that read the posts in this group have a
    fully functionl brain. :(

    --
    Duende
     
    Wipkip, Oct 19, 2003
    #9
  10. picayunish

    picayunish Guest

    brucie wrote in news:bmpteb$q4kfa$-berlin.de:
    > In post <asZjb.516$2o2.15099@amstwist00>
    > picayunish said...
    >
    >> I'm trying to activate an alternative style sheet by clicking on a
    >> hyperlink.

    >
    > http://usenet.alt-html.org/styles/css-changer-thingy.php


    I noticed in a style sheet (e.g. style04.css) the following string
    *{color:black;background-color:#FFC066;}

    Why using the * and not e.g. body {color:black;background-color:#FFC066;} ?
    --
    Edwin van der Vaart
    http://www.semi-conductor.nl/ Links to Semiconductors sites
    http://members.chello.nl/e.vandervaart/ Experimental site
     
    picayunish, Oct 19, 2003
    #10
  11. picayunish

    brucie Guest

    In post <ReCkb.796$2o2.15876@amstwist00>
    picayunish said...

    >> http://usenet.alt-html.org/styles/css-changer-thingy.php


    > I noticed in a style sheet (e.g. style04.css) the following string
    > *{color:black;background-color:#FFC066;}
    > Why using the * and not e.g. body {color:black;background-color:#FFC066;} ?


    i'm just in the habit of always starting my css with '*' for common
    stuff. the file is just a demo, stop picking on me. <sob/>

    --
    brucie.
    20/October/2003 06:30:59 am
     
    brucie, Oct 19, 2003
    #11
  12. picayunish

    picayunish Guest

    Toby A Inkster wrote in news:p:
    > Fabian wrote:
    >
    >> Toby A Inkster wrote:
    >>> One improvement to the above script would be to add a default
    >>> stylesheet.

    >>
    >> And how should you do that? With an if then else structure?

    >
    > Well, I *was* going to leave it as an exercise to the reader, but since
    > you asked:
    >
    > <!DOCTYPE whatever>
    > <?php
    > $s = $_GET['style'];
    > if (!($s)) { $s = 'red'; } ?>
    >
    > <html>
    > <head>
    > <title>Example</title>
    > <link rel="stylesheet" type="text/css" media="screen,projection"
    > <?php echo ' href="styles/' . $s . '.css"'; ?> >


    :cool: !
    The php script (above) and a normal style sheet link works perfectly.
    http://www.semi-conductor.nl/test/test2.php (php scripts)
    http://www.semi-conductor.nl/test/test3.php (a style sheet link + php
    script & it validates :-D )
    --
    Edwin van der Vaart
    http://www.semi-conductor.nl/ Links to Semiconductors sites
    http://members.chello.nl/e.vandervaart/ Experimental site
     
    picayunish, Oct 19, 2003
    #12
  13. picayunish

    picayunish Guest

    brucie wrote in news:bmusmg$rac7a$-berlin.de:
    > In post <ReCkb.796$2o2.15876@amstwist00>
    > picayunish said...
    >
    >>> http://usenet.alt-html.org/styles/css-changer-thingy.php

    >
    >> I noticed in a style sheet (e.g. style04.css) the following string
    >> *{color:black;background-color:#FFC066;}
    >> Why using the * and not e.g. body
    >> {color:black;background-color:#FFC066;} ?

    >
    > i'm just in the habit of always starting my css with '*' for common
    > stuff. the file is just a demo, stop picking on me. <sob/>


    :-| | That's it !
    I go to my trailer ! :-| |
    --
    Edwin van der Vaart
    http://www.semi-conductor.nl/ Links to Semiconductors sites
    http://members.chello.nl/e.vandervaart/ Experimental site
     
    picayunish, Oct 19, 2003
    #13
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mike Strauss

    Activating JavaScript from C#

    Mike Strauss, Dec 19, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    5,952
    Elton Wang
    Dec 20, 2004
  2. Robert Rotstein

    activating a SOAP extension from the client

    Robert Rotstein, Jan 10, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    440
    Robert Rotstein
    Jan 10, 2006
  3. Replies:
    0
    Views:
    526
  4. Rajive Narain
    Replies:
    0
    Views:
    1,936
    Rajive Narain
    Sep 18, 2009
  5. Ken Varn
    Replies:
    0
    Views:
    478
    Ken Varn
    Apr 26, 2004
Loading...

Share This Page