Forum Moderators: coopster

Message Too Old, No Replies

Problem with comparison operator

greater than comparison problem

         

kimm

5:17 pm on Dec 16, 2004 (gmt 0)

10+ Year Member



Can anyone tell me what is wrong with this?

$num_Pages = 147;
$max_pages_to_show = 20;

if ($max_pages_to_show <= $num_pages) {
print "less than";
} else {
print "more than";
}

I have used is_int to make sure the values are integers, yet this code consistently prints "more than".

What am I doing wrong?

pete_m

5:18 pm on Dec 16, 2004 (gmt 0)

10+ Year Member



PHP variable names are case sensitive.

You are setting $num_Pages but are comparing $num_pages

[edited by: pete_m at 5:20 pm (utc) on Dec. 16, 2004]

WestpointStevens

5:19 pm on Dec 16, 2004 (gmt 0)

10+ Year Member



My first response is get rid of the <= and make it <.

Secondly, what are you trying to do?

coopster

5:33 pm on Dec 16, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, kimm.

pete_m is correct, variable names are case-sensitive [php.net] and a nice way to catch these simple errors is to turn on error_reporting() [php.net] in your development environment.

kimm

5:44 pm on Dec 16, 2004 (gmt 0)

10+ Year Member



case-sensitive...that's it!

ok, thank you so much...I feel like a dope!

I appreciate the quick reply..this will be one mistake that I never forget!