For Programmers: Free Programming Magazines  


Home > Archive > PHP DB > February 2008 > Re: [PHP-DB] How to recognize which 'case' is being echoed by switch statement









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: [PHP-DB] How to recognize which 'case' is being echoed by switch statement
Stut

2008-02-22, 8:00 am


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/
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com