Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > BOOK: Beginning PHP 5.3
|
BOOK: Beginning PHP 5.3
This is the forum to discuss the Wrox book Beginning PHP 5.3 by Matt Doyle; ISBN: 978-0-470-41396-8
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP 5.3 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 August 11th, 2011, 12:25 AM
Authorized User
 
Join Date: Jun 2011
Posts: 51
Thanks: 9
Thanked 0 Times in 0 Posts
Send a message via MSN to nawar youssef
Default why the second if statement does not work?

hey, it is not a really important problem for me because I know it something maybe missing or wrong I did by mistake but I like to ask to give me a right view. this is my code and when I run it the second if does not work it is the same example on the page 54 :

<?php
$widget = 30;
if($widget >= 30) {
echo "we have more than 30 widgets in here";
} else if( $widget == 30) {
echo "we have exactly 30 widgets in here";
} else {
echo "we have less than 30 widgets in here";
}
?>

thanks
 
Old September 11th, 2011, 08:49 AM
Authorized User
 
Join Date: May 2010
Posts: 70
Thanks: 4
Thanked 6 Times in 6 Posts
Send a message via Yahoo to GeneBuchite
Default Why the second it does not work

The first if statement (
Code:
if($widget >= 30)
) reads ... if @widget is Greater than or equall to 30... which evaluates to true, is being run so the else if is skipped over, even though the else evaluates to true, the first if is read by the compiler first, then because it is true, the compiler skips the else statement.

the easiest fix is to change the if to :
Code:
 if($widget >= 31) {}
Then the if evaluates to false, the else if evaluates to true.
The Following User Says Thank You to GeneBuchite For This Useful Post:
nawar youssef (September 12th, 2011)
 
Old September 12th, 2011, 01:41 AM
Authorized User
 
Join Date: Jun 2011
Posts: 51
Thanks: 9
Thanked 0 Times in 0 Posts
Send a message via MSN to nawar youssef
Default OPPSSS !!!!!!!

yea you right, thanks I missed that, it is a simple but I do not how I missed it
thans so much





Similar Threads
Thread Thread Starter Forum Replies Last Post
SMS API does not work online but work fine offline. Tonik Beginning PHP 1 January 4th, 2013 08:30 AM
Chapter 1 Ctrl+F5 don't work, F5 does work? jimboak BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 7 June 29th, 2008 03:46 AM
READPAST Hint in SELECT statement won't work mike_abc SQL Server 2000 0 June 29th, 2005 08:08 AM
"On Error.." statement does not work mike123abc Access 3 November 14th, 2003 03:15 PM





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