Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-15-2012, 11:31 AM   PM User | #1
docock
Regular Coder

 
Join Date: Feb 2007
Posts: 191
Thanks: 18
Thanked 1 Time in 1 Post
docock is an unknown quantity at this point
Question higher number check fails

I'm kinda puzzled by this..

- I retrieve a value of a db field and store it into the variable $numbers.
- I count the number of records in an other database table and store that value in $num_rows.

If the value in $num_rows is higher then $numbers the user gets a warning.

My problem is that the warning is allways displayed even if the value of $num_rows is lower then $numbers.

For example, the coding below displays this:
test mymail@live.nl15max reached.

($num_rows is 1, and $numbers is 5 in this case)

Obviously the higher number check fails, since $num_rows is less then $numbers. How to solve this issue?


Code:
$num_rows = mysql_num_rows($resultaat)+1;

echo $code, $email,$num_rows,$numbers;

if ($num_rows>$numbers){echo "max reached.";exit;}
docock is offline   Reply With Quote
Old 11-15-2012, 02:33 PM   PM User | #2
Fumigator
UE Antagonizer


 
Fumigator's Avatar
 
Join Date: Dec 2005
Location: Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
Posts: 7,686
Thanks: 42
Thanked 637 Times in 625 Posts
Fumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of light
From your echo statement it's possible $num_rows is = 15 and $numbers is null. Since we can't see where $numbers got assigned a value I'd say this may be what's happening. If you wrote your echo statement a bit more clearly then you might see what's really going on-- obviously 1 is not greater than 5 and PHP knows that

Try using var_dump() on the two variables-- that will tell you if the variable types are numeric or strings.
__________________
Fumigator is offline   Reply With Quote
Old 11-15-2012, 02:38 PM   PM User | #3
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,042
Thanks: 8
Thanked 1,029 Times in 1,020 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
hmmm

See what this does:
just wondering if it's an issue of syntax (or formation of the "if" statement) ...
PHP Code:

$num_rows 
mysql_num_rows($resultaat)+1;

echo 
$code$email,$num_rows,$numbers;

if(
$num_rows $numbers){
echo 
"max reached.";
}
else{
echo 
"ok";


.
mlseim is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:41 AM.


Advertisement
Log in to turn off these ads.