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
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

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.