Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > BOOK: PHP and MySQL 24-Hour Trainer
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: PHP and MySQL 24-Hour Trainer
This is the forum to discuss the Wrox book PHP and MySQL 24-Hour Trainer by Andrea Tarr ; ISBN: 978-1-1180-6688-1
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: PHP and MySQL 24-Hour Trainer section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old June 4th, 2015, 04:28 AM
Registered User
Points: 5, Level: 1
Points: 5, Level: 1 Points: 5, Level: 1 Points: 5, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2015
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Lesson 7's Try It

Hey guys,

In the Lesson 7's Try It activity, towards the end of it, there is a switch statement:

Code:
switch (isset($_GET['content'])) :
	case 'gents' :
	case 'sporting' :
	case 'women' :
		include 'content/catnav.php';
	endswitch;
The code looks perfectly normal, but at this stage, the sidebar is showing on the "about" page too, even when we did not add it to the switch statement. Am I missing something?

I did resort to using if-else statements that work flawlessly though.
Reply With Quote
  #2 (permalink)  
Old August 23rd, 2015, 09:20 AM
Registered User
Points: 11, Level: 1
Points: 11, Level: 1 Points: 11, Level: 1 Points: 11, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2015
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi, shahz -

just came here to ask about this code as well.

i think what's happening is that this line:

Code:
switch (isset($_GET['content']))
is evaluating to "true" (because isset() returns a boolean)... and then perhaps after that _any_ non-null value of $_GET['content'] will be cast to "true" and trigger the case.

seems to me that the switch condition should instead be

Code:
switch ($_GET['content'])  // because we want to switch based on the content!
however this results in errors where "content" is not set, so it all needs to be wrapped in an "if" statement that evaluates isset().

(SPOILER ALERT):

Code:
<?php
		if (isset($_GET['content'])):
				switch ($_GET['content']):
					case 'gents':
					case 'sporting':
					case 'women':
						include 'content/catnav.php';
				endswitch;
		endif;
?>
works as expected:

- subnav links present on category pages for Gents, Sporting, Women
- subnav links not present on home, about, categories pages

Last edited by nbnyc; August 23rd, 2015 at 09:26 AM.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Try It - Lesson 7 oviera5 BOOK: Stephens' C# Programming with Visual Studio 2010 24-Hour Trainer 3 January 18th, 2013 12:25 PM
Lesson 9 ikocijan BOOK: Java Programming 24-Hour Trainer by Yakov Fain 1 November 27th, 2012 12:11 PM
Lesson 4 Femi Sonuga BOOK: Knight's Microsoft Business Intelligence 24-Hour Trainer 0 November 25th, 2011 09:25 AM
Lesson 9 MTMike BOOK: Knight's Microsoft Business Intelligence 24-Hour Trainer 3 November 3rd, 2011 01:51 PM
Lesson 4 Mtheys BOOK: Java Programming 24-Hour Trainer by Yakov Fain 3 September 15th, 2011 05:02 AM



All times are GMT -4. The time now is 08:33 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.