Wrox Programmer Forums
|
BOOK: Beginning PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143
This is the forum to discuss the Wrox book Beginning PHP 6, Apache, MySQL 6 Web Development by Timothy Boronczyk, Elizabeth Naramore, Jason Gerner, Yann Le Scouarnec, Jeremy Stolz; ISBN: 9780470391143
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143 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 March 25th, 2010, 05:54 PM
Registered User
 
Join Date: Mar 2010
Posts: 7
Thanks: 2
Thanked 0 Times in 0 Posts
Default Chapter 2, Page 76, Exercise 3

The code is given on page 650 as below:
Code:
<body>
<?php 
date_default_timezone_set('UK/London');

if (date('G') >= 5 && date('G') <=11) {
echo '<h1>Good Morning!</h1>';
}
else if (date('G') >=12 && date('G') <=18) {
echo '<h1>Good Afternoon!</h1>';
}
else if (date('G') >=19 && date('G') <=4) {
echo '<h1>Good Evening!</h1>';
}
 ?>
</body>
However, the time is currently 21.48 and the page which is returned is blank. The reason is obviously that none of the above three else if statements are true. 21 is greater than 19 but is not less than or equal to 4 so obviously nothing is returned. Surely the last statement should be simply :
Code:
else {
echo '<h1>Good Evening!</h1>';
}
ie if the first two are false then just do this. I've amended my code to the above and it works fine with no error messages. My question is, is this correct programming or was I just lucky?

Thanks, Chastini.

Last edited by Chastini; March 25th, 2010 at 08:09 PM.. Reason: coding brackets
 
Old March 25th, 2010, 09:24 PM
Friend of Wrox
 
Join Date: Dec 2008
Posts: 238
Thanks: 2
Thanked 20 Times in 19 Posts
Default

Your way is correct and better.

If you want to follow the original code, the last && there should really be ||.
The Following User Says Thank You to PeterPeiGuo For This Useful Post:
Chastini (March 26th, 2010)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 7 - Exercise [email protected] BOOK: Beginning PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143 2 March 16th, 2010 07:32 PM
Chapter 3 exercise 2 weekapaugh BOOK: Beginning C# 3.0 : An Introduction to Object Oriented Programming ISBN: 978-0-470-26129-3 2 March 11th, 2010 02:28 AM
chapter 9 exercise michaelcode BOOK: Beginning ASP.NET 1.0 1 April 9th, 2006 03:56 PM
CH 3 pg 76 wadesmart BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 2 October 26th, 2003 08:46 PM





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