How to recognize which 'case' is being echoed by switch statement

--Apple-Mail-7--114873320
Content-Type: text/plain;
charset=US-ASCII;
format=flowed;
delsp=yes
Content-Transfer-Encoding: 7bit

Hi,

This is my first time using php in my site navigation, I have the code
for all the pages in one file and I am using the switch statement to
change between them.

This is working great but I am now trying to change the css id of the
current page's navbar link. How do I get my script to recognize which
case is currently being echoed by the switch statement?

If you want to see the page in action without php in the navbar visit
here: http://www.publikdesign.com


Here is the code:

<html>
<head>
<link href="css/styles.css" rel="stylesheet" type="text/css">
</head>
<body>


<div id="page-container">



<!--- Header --->

<div id="header">

<div id="nav">

<ul>
<?php
$page = case;
if ( $page = "contact" ) {
echo "<li id=\"contact-active\"></li>"; }

else {
echo "<li id=\"contact\"><a href=\"./?page=contact\">Contact</
a></li>"; }
?>

<?php
if ( $page = "portfolio" ) {
echo "<li id=\"portfolio_active\"></li>"; }

else {
echo "<li id=\"portfolio\"><a href=\"./?page=portfolio
\">Portfolio</a></li>"; }
?>

<?php
if ( $page = "home" ) {
echo "<li id=\"home-active\"></li>"; }

else {
echo "<li id=\"home\"><a href=\"./?page=home\">Home</a></li>"; }

?>



</ul>

</div>

</div>


<!--- End Header --->


<!--- Main --->

<div id="main-content">


<?php

switch($_GET['page']) {

case "contact":
echo "<!--- Left Content --->

<div id=\"left-content\">

<div id=\"left-top\">
<ul>
<li><Strong>Phone</Strong> 0437 988 399</li>
<li>
</li>
<li><Strong>eMail</Strong> <a href=\"mailto:tdaff [at] publikdesign.com
\">tdaff [at] publikdesign.com</a></li>
</ul>
</div>

</div>


<!--- Right Content --->

<div id=\"right-content\">



</div>";
break;

case "portfolio":
echo "<!--- Left Content --->

<div id=\"left-content\">


<img src=\"images/portfolio/portfolio_heading.gif\"
alt=\"Portfolio\" />

<div id=\"port_img1\">
<img src=\"images/portfolio/kdev_logo.gif\" alt=\"K
Development Lofo\" />
<p class=\"caption-link\"><a href=\"?page=kdev
\">Click to Expand</a></p>
</div>

<div id=\"port_img2\">
<img src=\"images/portfolio/kmg_logo.gif\" alt=
\"Katmandog Logo\" />
<p class=\"caption-link\"><a href=\"http://www.katmandog.biz
\" target=\"_blank\">Click to visit website</a></p>
</div>


</div>


<!--- Right Content --->

<div id=\"right-content\">


<div id=\"port_img3\">
<img src=\"images/portfolio/isl_logo.gif\" alt=
\"Island Healing Logo\" />
<p class=\"caption-link\"><a href=\"?page=isl\">Click
to Expand</a></p>
</div>

<div id=\"port_img4\">
<img src=\"images/portfolio/re_logo.gif\" alt=
\"Roaming Earth Logo\" />
<p class=\"caption-link\"><a href=\"?page=re\">Click
to Expand</a></p>
</div>

</div>";
break;

case "home":
echo "<!--- Left Content --->

<div id=\"left-content\">

<div id=\"left-top\">
<img src=\"images/dsgn_services.gif\" alt=\"Graphic
Design Services\" width=\"327\" height=\"28\" />
<p>Publik provides a full range of graphic design
services, from business cards and letterheaders, to product catalogues
and promotional brochures. We will bring your project from concept to
print in the most cost effective and professional manner.</p>
</div>

<div id=\"left-bottom\">
<img src=\"images/webdevel.gif\" alt=\"Web Development
\" />
<p>The world wide web has grown into the most
powerful marketing tool available to a business. From a concreter to a
department store, the internet can not be overlooked as an important
tool in bringing clients to your business. Publik Design provides all
manner of web services from static pages to fully dynamic web
applications.</p>
</div>

</div>


<!--- Right Content --->

<div id=\"right-content\">

<div id=\"right-top\">
<img src=\"images/kdev1.gif\" alt=\"K Development
Business Card Design\" />
</div>

<div id=\"right-bottom\">
<img src=\"images/katmandog_thumb.gif\" alt=
\"Katmandog Pet Shop Thumbnail\" />
</div>

</div>";
break;

case "kdev":
echo "<!--- Left Content --->

<div id=\"left-content\">


<img src=\"images/portfolio/portfolio_heading.gif\"
alt=\"Portfolio\" />
<p><a href=\"?page=portfolio\">Back</a></p>

<div id=\"large1\">
<img src=\"images/portfolio/kdev_expanded.gif\" alt=
\"K Development\" />
</div>



</div>";
break;

case "isl":
echo "<!--- Left Content --->

<div id=\"left-content\">


<img src=\"images/portfolio/portfolio_heading.gif\" alt=
\"Portfolio\" />
<p><a href=\"?page=portfolio\">Back</a></p>
<div id=\"large1\">
<img src=\"images/portfolio/isl_expanded.gif\" alt=
\"K Development\" />
</div>




</div>";
break;

case "re":
echo "<!--- Left Content --->

<div id=\"left-content\">


<img src=\"images/portfolio/portfolio_heading.gif\" alt=
\"Portfolio\" />
<p><a href=\"?page=portfolio\">Back</a></p>
<div id=\"large1\">
<img src=\"images/portfolio/re_expanded.gif\" alt=\"K
Development\" />
</div>



</div>";
break;

default:
echo "<!--- Left Content --->

<div id=\"left-content\">

<div id=\"left-top\">
<img src=\"images/dsgn_services.gif\" alt=\"Graphic
Design Services\" width=\"327\" height=\"28\" />
<p>Publik provides a full range of graphic design
services, from business cards and letterheaders, to product catalogues
and promotional brochures. We will bring your project from concept to
print in the most cost effective and professional manner.</p>
</div>

<div id=\"left-bottom\">
<img src=\"images/webdevel.gif\" alt=\"Web Development
\" />
<p>The world wide web has grown into the most
powerful marketing tool available to a business. From a concreter to a
department store, the internet can not be overlooked as an important
tool in bringing clients to your business. Publik Design provides all
manner of web services from static pages to fully dynamic web
applications.</p>
</div>

</div>


<!--- Right Content --->

<div id=\"right-content\">

<div id=\"right-top\">
<img src=\"images/kdev1.gif\" alt=\"K Development
Business Card Design\" />
</div>

<div id=\"right-bottom\">
<img src=\"images/katmandog_thumb.gif\" alt=
\"Katmandog Pet Shop Thumbnail\" />
</div>

</div>";
break;

}

?>

</div>

<!--- End Main --->

<!--- Footer --->

<div id="footer">

<div id="footer-content">
<p>©2008 Publik Design
<a href="index.html">Home</
a> Portfolio Contact</p>
</div>
</div>

</div>

</body>
</html>
--Apple-Mail-7--114873320--
Tim Daff [ Fr, 22 Februar 2008 12:01 ] [ ID #1925338 ]

Re: How to recognize which 'case' is being echoed by switch statement

On 22 Feb 2008, at 11:01, Tim Daff wrote:
> <?php
> $page = case;
> if ( $page = "contact" ) {
> echo "<li id=\"contact-active\"></li>"; }
>
> else {
> echo "<li id=\"contact\"><a href=\"./?page=contact\">Contact</
> a></li>"; }
> ?>


$page = case; will be raising a notice which you're obviously not
seeing. So, step 1 is to edit PHP.ini on your development machine so
error_reporting is E_ALL, and display_errors is on. You'll need to
restart your web server for this change to take effect.

The case keyword is not valid outside a switch block. What you want to
be doing is comparing "contact" etc with $_GET['page'] which is the
variable the switch statement is using.

Additionally you are using a single = which is the assignment
operator, so each if statement is assigning the quoted string to $page
not testing for it. You need to use == to do that.

I would suggest you buy a book on PHP for beginners, or Google for an
introductory tutorial because these are pretty basic syntax mistakes.

-Stut

--
http://stut.net/

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Stut [ Fr, 22 Februar 2008 13:31 ] [ ID #1925339 ]

RES: How to recognize which 'case' is being echoed by switch statement

Quite sure this is not what you mean:

> $page = case;
> if ( $page = "contact" ) {

but instead

> $page = case;
> if ( $page == "contact" ) {



-----Mensagem original-----
De: Stut [mailto:stuttle [at] gmail.com]
Enviada em: sexta-feira, 22 de fevereiro de 2008 09:31
Para: Tim Daff
Cc: php-db [at] lists.php.net
Assunto: Re: [PHP-DB] How to recognize which 'case' is being echoed by
switch statement

On 22 Feb 2008, at 11:01, Tim Daff wrote:
> <?php
> $page = case;
> if ( $page = "contact" ) {
> echo "<li
id=\"contact-active\"></li>"; }
>
> else {
> echo "<li id=\"contact\"><a
href=\"./?page=contact\">Contact</
> a></li>"; }
> ?>


$page = case; will be raising a notice which you're obviously not seeing.
So, step 1 is to edit PHP.ini on your development machine so error_reporting
is E_ALL, and display_errors is on. You'll need to restart your web server
for this change to take effect.

The case keyword is not valid outside a switch block. What you want to be
doing is comparing "contact" etc with $_GET['page'] which is the variable
the switch statement is using.

Additionally you are using a single = which is the assignment operator, so
each if statement is assigning the quoted string to $page not testing for
it. You need to use == to do that.

I would suggest you buy a book on PHP for beginners, or Google for an
introductory tutorial because these are pretty basic syntax mistakes.

-Stut

--
http://stut.net/

--
PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit:
http://www.php.net/unsub.php

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Thiago Pojda [ Fr, 22 Februar 2008 13:46 ] [ ID #1925340 ]

Re: How to recognize which 'case' is being echoed by switch statement

On Fri, Feb 22, 2008 at 6:01 AM, Tim Daff <timdaff [at] gmail.com> wrote:
> Hi,
>
> This is my first time using php in my site navigation, I have the code
> for all the pages in one file and I am using the switch statement to
> change between them.
[snip!]

None of your code included a case/switch piece. This is probably
what you mean:

<?
$page = basename($_SERVER['PHP_SELF']);

switch($page) {
case "contact.php":
$css = "<li id=\"contact-active\"></li>";
break;
case "portfolio.php":
$css = "<li id=\"portfolio-active\"></li>";
break;
case "whoweare.php":
$css = "<li id=\"whoweare-active\"></li>";
break;
default:
$css = "<li id=\"home-active\"></li>";
break;
}
?>

--
</Dan>

Daniel P. Brown
Senior Unix Geek
<? while(1) { $me = $mind--; sleep(86400); } ?>

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
parasane [ Fr, 22 Februar 2008 16:45 ] [ ID #1925342 ]
PHP » gmane.comp.php.database » How to recognize which 'case' is being echoed by switch statement

Vorheriges Thema: Plant Extracts and Our Factory
Nächstes Thema: Best ORM?