Undefined offset error issue !!! |
[eluser]mythilisubramanyam[/eluser]
for($i=0;$i<$count;$i++) { $data = array('dSubjectName' => $name1[$i], 'dSubjectType' => $type1[$i]); $this->db->where('dSubject_id', $id1[$i]); $this->db->where('dSub_id', $sId); $this->db->update('tbl_subjectdetails_master', $data); } ////for this code i'm getting an error : A PHP Error was encountered Severity: Notice Message: Undefined offset: 3 Filename: models/adminModel.php Line Number: 647 ////In the for loop its not taking "<" symbol, but the update function is running, without any issue, the only error is for "<" symbol, so can any one help me for this issue,
[eluser]Dam1an[/eluser]
count is a reserved word in PHP, so naming a variable 'count' will most likely be the cause of the problem, try giving it a differant name
[eluser]mythilisubramanyam[/eluser]
count is not a problem, if i change the name also, i'm getting the same error, but, in for loop if "<" symbol is replaced by "=" symbol, no error occurs, so problem is with the "<" symbol, what will i do now????
[eluser]Dam1an[/eluser]
I don't really think the '<' is the problem here You get the undefined offset error when you try to access a position in an array which doesn't exist, in this case you're trying to access item at position 3 (the 4th item as arrays start at 0) and one of those arrays aren't big enough What do you get if you do print_r on each array?
[eluser]garymardell[/eluser]
Maybe you actually want to write Code: for($i=0;$i=<$count;$i++) Which line actually is 647, and can you give a print_r(); of the $data array please.
[eluser]Evil Wizard[/eluser]
you need to make sure the three arrays you are using are infact of the same lenth and equal to or greater than the $count value, have a look at the line 647 and see which array has less elements than the value of $count, alse echo out the value of $i during the loop to see if the loop works at least once.
[eluser]xwero[/eluser]
[quote author="Dam1an" date="1246458137"]count is a reserved word in PHP[/quote] Where did you find count is a reserved word in php? Not in the official documentation i think.
[eluser]Evil Wizard[/eluser]
[quote author="xwero" date="1246460537"][quote author="Dam1an" date="1246458137"]count is a reserved word in PHP[/quote] Where did you find count is a reserved word in php? Not in the official documentation i think.[/quote] count() is a php function which used to have sizeof() as an alias for returning the total number of elements in an array regardless of key index values.
[eluser]Dam1an[/eluser]
[quote author="xwero" date="1246460537"][quote author="Dam1an" date="1246458137"]count is a reserved word in PHP[/quote] Where did you find count is a reserved word in php? Not in the official documentation i think.[/quote] I can't remember, I just know it's caused me problems in the past :-S (Am I even thinking of PHP or was it some other language?) |
Welcome Guest, Not a member yet? Register Sign In |