Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 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 March 25th, 2010, 06:54 PM
Registered User
 
Join Date: Mar 2010
Location: Plymouth UK
Posts: 7
Thanks: 2
Thanked 0 Times in 0 Posts
Send a message via Skype™ to Chastini
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 09:09 PM. Reason: coding brackets
Reply With Quote
  #2 (permalink)  
Old March 25th, 2010, 10:24 PM
Friend of Wrox
 
Join Date: Dec 2008
Location: , , .
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 ||.
Reply With Quote
The Following User Says Thank You to PeterPeiGuo For This Useful Post:
Chastini (March 26th, 2010)
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
Chapter 7 - Exercise rickymartini76@yahoo.it BOOK: Beginning PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143 2 March 16th, 2010 08: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 04: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



All times are GMT -4. The time now is 07:42 PM.


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