473,498 Members | 1,875 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Invalid argument supplied for foreach()?

KeredDrahcir
426 Contributor
I have a script that needs to compare some data in an array to data in sepcific locations in a session array. The first time I run the foreach there's no problem but the second time it fails but the data is the same. Can anyone help me?
Expand|Select|Wrap|Line Numbers
  1. foreach ($arr1 as $equ)
  2. {
  3.   if ($_SESSION['array'][$equ+6]==51)
  4.   {
  5.     list($equId, $equtitel)=equ_location($db,$id,$equ);
  6.     if ($arr1_effect[$count]==1)
  7.     {
  8.       $effect="temp";
  9.     }
  10.     elseif ($arr1_effect[$count]==0)
  11.     {
  12.       $effect="total";
  13.       $_SESSION['array'][$number+26]=0;
  14.     }
  15.     $arr1=1;
  16.     break;
  17.   }
  18.   else
  19.   {
  20.     foreach ($arr1 as $equ)
  21.     {
  22.       DO STUFF
  23.     }
  24.   }
  25. }
  26.                           {
Can anyone suggest why the second foreach isn't working?
Aug 23 '13 #1
10 2429
Rabbit
12,516 Recognized Expert Moderator MVP
It's because your second loop uses the same variable as the first one.
Aug 23 '13 #2
KeredDrahcir
426 Contributor
Does that mean I need to rename $equ?

That's wierd. It worked fine to begin with which was why I couldn't understand it.

Thanks.
Aug 24 '13 #3
Rabbit
12,516 Recognized Expert Moderator MVP
I don't know what you mean by "to begin with" because that is vague. But almost never will you have an embedded loop where you change the outer loops variables.
Aug 24 '13 #4
KeredDrahcir
426 Contributor
Is it $arr1 or $equ I need to change becuase I changed the later, and it still didn't work.
Aug 24 '13 #5
Rabbit
12,516 Recognized Expert Moderator MVP
It's the $equ you have to change. If it still doesn't work, that means you have a logic error somewhere and you need to define what that means.
Aug 25 '13 #6
KeredDrahcir
426 Contributor
Okay, thanks. I'll try it again. When I said it worked previously, I meant that I had to code mini pulsating data from a database. I'd had different sets of data that I needed to minipulate in the same way. I wrote the code to do what I wanted and told it to look at a column in each table that told from each set of the data that record was from.
When I tested it to begin with I had only one set of data and the offending line worked, it only stopped working when I added a second set of data. Maybe it's something in the data that didn't occur in the first test. Maybe I should check the functions too.
Aug 25 '13 #7
Rabbit
12,516 Recognized Expert Moderator MVP
That's still very vague. It would help to see some sample data and results.

I don't understand what you mean by: "mini pulsating data" and "look at a column in each table that told from each set of the data that record was from"
Aug 25 '13 #8
KeredDrahcir
426 Contributor
mini pulating data could easily be an auto correct from a mispelling of minipulating.

Thanks for your help. I've worked out where the problem is and what I've done wrong. I've also got a pretty good idea of why this problem never occured before and I think I know how to fix it. I'll let you know how I do, or if I need anymore help.
Aug 25 '13 #9
KeredDrahcir
426 Contributor
I've fixed it. Thanks for all your help. I hope this helps anyone else who has the same problem.
Aug 25 '13 #10
Rabbit
12,516 Recognized Expert Moderator MVP
Please post your solution in case someone runs into the same problem.
Aug 26 '13 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1391
by: llevi | last post by:
Hi there, My aspnet_state.exe service is failing to start due to an invalid argument. Does anyone know what arguments are required/valid for this service. I am running XP pro, .NET Framework v...
5
5432
by: Nuno Magalhaes | last post by:
I'm trying to set a multicast server but I get "Invalid argument" when setting multicast options. Below is the code that gives me problems more precisely in SetSocketOption with the AddMembership...
0
930
by: oaksong | last post by:
I'm unable to connect to the local host. My company uses blackice and I've been told they won't open more than one port. I have a port open and followed the directions to point to it. (I set...
4
3370
by: robert | last post by:
On a server the binary (red hat) installed python2.4 and also a fresh compiled python2.5 spits "sem_post: Invalid argument". What is this and how can this solved? Robert ============== ...
1
1328
by: guoxin | last post by:
Hi All, May i know how to rectify the following php error? Thanks folks Warning: Invalid argument supplied for foreach() in /home/alan/do_add-user.php on line 36 do_add-user.php.php on...
1
1616
by: BryanA | last post by:
Something seems to be wrong with this function and I can't figure out why it is failing. The error that it gives is; Invalid argument supplied for foreach() . function transposition($words){...
14
3325
by: rashgang | last post by:
i have dynamically created checkbox which will like yahoo mail if check box selected it will highlight a row but deleteall function is not working plz chek it function doDeleteAll($objArray){ ...
4
6277
by: mattehz | last post by:
Hey there, I am trying to upload old source files and came across these errors: Warning: Invalid argument supplied for foreach() in /home/mattehz/public_html/acssr/trunk/inc_html.php on line 59...
1
2260
by: mahhood | last post by:
Here is the complete code. <?php // ****: holder.php - v. 5.03 // PRELIMINARIES: // Get Includes:
0
2519
by: danishashfaq | last post by:
This code works fine on my XP machine, but when I run it on another XP machine it gives error "An invalid argument was supplied." on Socket.IOControl method. All machines have wireless connection....
0
7208
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6890
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5464
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4593
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3095
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3085
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1423
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
657
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
292
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.