[PHP-DB] How to recognize which 'case' is being echoed by switch statement
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 liStrongPhone/Strong 0437 988 399/li libr //li liStrongeMail/Strong a href=\mailto:[EMAIL PROTECTED] \[EMAIL PROTECTED]/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\ / pPublik 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 \ / pThe 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
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
Re: [PHP-DB] How to recognize which 'case' is being echoed by switch statement
On Fri, Feb 22, 2008 at 6:01 AM, Tim Daff [EMAIL PROTECTED] 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