Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 4th, 2015, 04:28 AM
Registered User
 
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.
 
Old August 23rd, 2015, 09:20 AM
Registered User
 
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..





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 01:25 PM
Lesson 9 ikocijan BOOK: Java Programming 24-Hour Trainer by Yakov Fain 1 November 27th, 2012 01:11 PM
Lesson 4 Femi Sonuga BOOK: Knight's Microsoft Business Intelligence 24-Hour Trainer 0 November 25th, 2011 10: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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.