Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

activating alternative style sheet with php

2 views
Skip to first unread message

picayunish

unread,
Oct 17, 2003, 5:46:59 PM10/17/03
to
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


Toby A Inkster

unread,
Oct 17, 2003, 6:11:51 PM10/17/03
to
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

picayunish

unread,
Oct 17, 2003, 7:12:27 PM10/17/03
to

Thanx Toby.
It's getting late. I'll try it later of the day, so good night.

picayunish

unread,
Oct 19, 2003, 8:04:43 AM10/19/03
to
brucie wrote in news:bmpteb$q4kfa$1...@ID-117621.news.uni-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

Interresting, I'll experiment with it.

picayunish

unread,
Oct 19, 2003, 8:08:42 AM10/19/03
to
Toby A Inkster wrote in news:pan.2003.10.17....@goddamn.co.uk:
> 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.

Fabian

unread,
Oct 19, 2003, 12:06:32 PM10/19/03
to
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/


Toby A Inkster

unread,
Oct 19, 2003, 12:53:30 PM10/19/03
to
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>
======================================================================

Wipkip

unread,
Oct 19, 2003, 3:39:42 PM10/19/03
to
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


picayunish

unread,
Oct 19, 2003, 4:11:46 PM10/19/03
to
brucie wrote in news:bmpteb$q4kfa$1...@ID-117621.news.uni-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;} ?

picayunish

unread,
Oct 19, 2003, 4:51:52 PM10/19/03
to
Toby A Inkster wrote in news:pan.2003.10.19....@goddamn.co.uk:
> 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"'; ?> >

8-) !
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 )

picayunish

unread,
Oct 19, 2003, 4:55:48 PM10/19/03
to
brucie wrote in news:bmusmg$rac7a$1...@ID-117621.news.uni-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 ! :-| |

0 new messages