For Programmers: Free Programming Magazines  


Home > Archive > PHP DB > February 2008 > RES: [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 RES: [PHP-DB] How to recognize which 'case' is being echoed by switch statement
Thiago Pojda

2008-02-22, 8:00 am

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@gmail.com]
Enviada em: sexta-feira, 22 de fevereiro de 2008 09:31
Para: Tim Daff
Cc: php-db@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
Sponsored Links







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

Copyright 2008 codecomments.com