At 11/27/2006 02:11 PM, Ross wrote:
$text_only = isset($_GET['text_only']) ? $_GET['text_only'] : 1;
if ($text_only==1) {
?>
<a href="<?php echo $_SERVER['PHP_SELF'];?>?text_only=0">off</a>
// import css here
<?
}
else {
?>
<a href="<?php echo $_SERVER['PHP_SELF'];?>?text_only=1">on</a></span>
// import css here
<?
}
?>
I'd begin by simplifying the logic and separating it from the HTML:
$text_only = isset($_GET['text_only']) ? $_GET['text_only'] : 1;
$onoff = ($text_only) ? 'on' : 'off';
echo <<<_
<a href="{$_SERVER['PHP_SELF']}?text_only=$text_only">$onoff</a>
_;
How can you import CSS after a hyperlink? Shouldn't it go in the
document head?
echo <<<_
<link href="textsize$text_only.css" rel="stylesheet" type="text/css" />
_;
That will link to either textsize0.css or textsize1.css depending on
the value of $text_only.
<?
$text_size = isset( $_REQUEST['text_size'] ) ? $_REQUEST['text_size'] : '';
switch ($text_size) {
case "medium":
?>
<link href="css/medium.css" rel="stylesheet" type="text/css" />
<?
break;
case "larger":
?>
<link href="css/larger.css" rel="stylesheet" type="text/css" />
<?
break;
case "largest":
?>
<link href="css/largest.css" rel="stylesheet" type="text/css" />
<?
break;
}
?>
Again, you don't need the switch block because the values you're
testing for map one-to-one with the values you're using in your output:
echo <<<_
<link href="css/$text_size.css" rel="stylesheet" type="text/css" />
_;
these work great independently but when I use one the other switches off.
any ideas how I can combine them?
If you need to remember two separate values through multiple
pageviews you can either:
a) include them both in each hyperlink so they're both refreshed each
time a link is clicked:
<a
href="{$_SERVER['PHP_SELF']}?text_only=$text_only&text_size=$text_size">$onoff</a>
b) or, more reasonably, store their values in the $_SESSION cookie so
you can read & write them as needed throughout the current session.
http://php.net/session
I use standard subroutines for getting their values, something like this:
if (isset($_GET[$argname]))
{
return $_GET[$argname];
}
elseif (isset($_SESSION[$argname]))
{
return $_SESSION[$argname];
}
In other words, if the value has been set by the last request from
the client, use that, otherwise fall back to the session value. In
other cases my fallback might be $_GET or $_POST to $_SESSION to $_COOKIE.
Regards,
Paul
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php