Welcome Guest, Not a member yet? Register   Sign In
Undefined offset error issue !!!
#1

[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,
#2

[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
#3

[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????
#4

[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?
#5

[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.
#6

[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.
#7

[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.
#8

[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.
#9

[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?)




Theme © iAndrew 2016 - Forum software by © MyBB