activating alternative style sheet with php

P

picayunish

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?
 
T

Toby A Inkster

picayunish said:
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.
 
P

picayunish

Toby A Inkster wrote in news:p[email protected]:
picayunish said:
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.
 
P

picayunish

Toby A Inkster wrote in news:p[email protected]:
picayunish said:
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.
 
F

Fabian

Toby said:
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).
 
T

Toby A Inkster

Fabian said:
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>
======================================================================
 
W

Wipkip

Toby said:
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. :(
 
B

brucie

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/>
 
P

picayunish

Toby A Inkster wrote in news:p[email protected]:
Fabian said:
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 )
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top