Jump to content

Recommended Posts

Just out of the blue, a fully functional page, without any changes made to it, is showing an error: Warning: Invalid argument supplied for foreach() in /path/file.php on line 169, line shown below:

 

foreach($rs_frd as $offset => $value):

 

How can I find out what's causing this error?

Wow! That's some serious and messy code I just had to review. Looks like the error is appearing when there's no results for that array. Can I add something that will show a more friend error on the page if there's no results for that array or if array doesn't exist (in case of no data)?

 

Thanks.

I would recommend using empty instead of isset here, isset will return TRUE even if the variable is empty.

 

Edit: going off of what Maq posted, somewhere in your code, where this array is generated is where you will want to look, your code should allow an empty array to even be created

That works, but I also need to place another if/then for endforeach, but I'm getting a parse sytax error:

 

if (is_array($rs_frd)) { 
	endforeach;
 }	

 

You can't conditionally close a loop. Control structures shouldn't, and thankfully don't, work that way. What you can do is break from the loop. Although I don't see how that would fit into your code anyway?

That works, but I also need to place another if/then for endforeach, but I'm getting a parse sytax error:

 

if (is_array($rs_frd)) { 
	endforeach;
 }	

yes I'm not really sure at all what you are trying to accomplish with this code that you posted? Perhaps give a little more information on the matter..

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.