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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx] 
Enviada em: sexta-feira, 22 de fevereiro de 2008 09:31
Para: Tim Daff
Cc: php-db@xxxxxxxxxxxxx
Assunto: 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

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


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux