Jump to content

else loop executing when should not


rubing

Recommended Posts

Hey all,

 

I am trying to limit the number of results presented to a client by allowing a limit variable passed in to a GET statement (e.g http://www.example.com/service.php?limit=4"&q=banana)

 

If they don't set a limit (or an improper one) I want the number of results to default to a high number.  So, I wrote the following code.  This code does not work when limit=0 ? 

 

if(!empty($_GET['limit']) && is_numeric($_GET['limit']))
{
	$limit=(int) $_GET['limit'];
}
//no limit, so set to ridiculously high number
else 
{
	$limit=1000000;
}

 

 

Strangely, however when this code executes the limit

Link to comment
https://forums.phpfreaks.com/topic/116262-else-loop-executing-when-should-not/
Share on other sites

,but the ELSE statement IS what's executing and it should not. 

 

when I say limit=1 or some other number everything is fine...$limit is assigned that number.

 

however, when I say limit=0, the script is executing the else statement, and then setting $limit=1000000.  There is no reason why it should do this!! 

 

In order to get 0 results I have to actually set limit=-1

 

 

So, basically what i'm saying is that my script is ONLY malfunctioning when I set limit=0

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.