Bill
Bill

Reputation: 77

Undefined offset Notice Seems Wrong

I am surprised and confused.

I have a fully working php web application that is throwing an Undefined offset warning notice and I cannot see why.

I use Codeigniter and have this call to a model:

$data = $this->clubinfo_model->get_data($club);

An array is returned and print_r confirms that the array is as I expected with the '0' array containing a number of key-value pairs. Here is the print_r output:

Array ( [0] => Array ( [clubID] => 18 [shortname] => Woodmere [fullname] => Woodmere Bridge Club [game1day] => x [DOW] => Thursday [game1time] => [game1location] => [director] => [readdirectory] => [offset] => [urlpath] => [webpage] => ) )

I then make this assignment:

$DOW = $data['0']['DOW'];

$DOW get the day of week.

Works fine.

But, php reports an error on the assignment line and says:

ERROR - 2015-01-05 05:50:00 --> Severity: Notice --> Undefined offset: 0 /home3/billhogs/public_html/ccbridgeclub/application/controllers/scores.php 71

Taking out the '0' index gets the expected results--the program does not work.

So, what is going on?

I assume this is unrelated, but the Codeignighter error log reports the Undefined offset warning notice twice. I have checked and the function with the strange error is only called once anywhere in the project. Actually, it is only called from an address fed to the default controller.

Bill

Upvotes: 0

Views: 174

Answers (1)

codename
codename

Reputation: 25

while assigning instead of $data['0']['DOW'] write $data[0]['DOW']

Upvotes: 0

Related Questions