Undefined index:

The usual apologies for being a newb & asking stupid questions… but I’m am using Codeigniter for a basic CRUD app.

elseif ($data['records']['qualified_lvl'] == 1)

all three of my else-if’s are telling me [‘qualified_lvl’] is an undefined index, but I’m able to print it out in the view… maybe it’s suppose to be a property instead of an index, but the syntax I thought I understood for that is returning undefined variable.
I suppose the view is adding the for each loop, but there seems to be something about the syntax that I am missing.
In the controller:

function i_wanna_mow() {	$this -> load -> model('membership_model');
		$data['records'] = $this -> membership_model -> getMOWERSRow();
		if ($data['records'] == NULL) {
			$data['main_content'] = 'i_wanna_mow';
			$this -> load -> view('includes/template', $data);
		} elseif ($data['records']['qualified_lvl'] == 1) {
			$data['main_content'] = 'i_wanna_mow';
			$this -> load -> view('includes/template', $data);
		} elseif ($data['records']['qualified_lvl'] == 2) {
			$data['main_content'] = 'i_wanna_mow';
			$this -> load -> view('includes/template', $data);
		} elseif ($data['records']['qualified_lvl'] == 3) {
			$data['main_content'] = 'i_wanna_mow';
			$this -> load -> view('includes/template', $data);
		} else {
			$data['main_content'] = 'i_wanna_mow';
			$this -> load -> view('includes/template', $data);		}
	}

and in the model it is calling…

function getMOWERSRow() {
		$this -> db -> where('username', $this -> session -> userdata('username'));
		$this->db->join('mowermen', 'mowermen.id =  members.id', 'left');

		$query = $this -> db -> get('members');

		if ($query -> num_rows == 1) {
			foreach ($query->result() as $row) {
				$data[] = $row;
			}
			return $data;}
	}

Just before that if, do a print_r($data[‘records’]) to see what that variable contains.

thanks Guido… maybe I’m using the wrong keywords, but all the threads for Undefined Index just indicate that I should dismiss the message cause it’s only a notice, but i’m actually trying to use it in the logic to fork a link to 4 possible destinations, depending on the member’s entry under [qualified_lvl] => 0 , as in 0 please fill out this form, oh 1, your application is under review, please check back in 3 to 4 days, etc…

Array ( [0] => stdClass Object ( [id] => 20 [first_name] => First Name [last_name] => Last Name [username] => Username [password] => 6711e155318212b3964dc647eb65e752 => [email]Email@Address.com [contact_number] => 888-888-8888 [street_address] => 0 [city] => City [state] => ST [zip_code] => 55555 [date_submitted] => 2012-09-03 [qualified_lvl] => 0 ) )

I’ve updated the controller, making test views to test new code now…

	function i_wanna_mow() {	$this -> load -> model('membership_model');
		$data['records'] = $this -> membership_model -> getMOWERSRow();
		
		foreach($data['records'] as $row) :
    			$lvl = $row->qualified_lvl;
    	endforeach;
		
		if ($lvl  = 0) {
			$data['main_content'] = 'i_wanna_mow';
			$this -> load -> view('includes/template', $data);
		} elseif ($lvl  = 1) {
			$data['main_content'] = 'i_wanna_mow';
			$this -> load -> view('includes/template', $data);
		} elseif ($lvl  = 2) {
			$data['main_content'] = 'i_wanna_mow';
			$this -> load -> view('includes/template', $data);
		} else {
			$data['main_content'] = 'i_wanna_mow';
			$this -> load -> view('includes/template', $data);
		}

	}

ok, figured it out, when I originally try using the for each loop I was wrapping it around all of my ifelse statements, that was unnecessary. Now I just leave it open for one line, which is all I need to extract the value & it’s best if that value is named anything besides what you just extracted it from, I think I may have been reassigning my value after retrieving it. Oh well, I feel smart again because it’s working now…

foreach($data[‘records’] as $row) :
$lvl = $row->qualified_lvl;
endforeach;

will only retrieve the last record as $lvl.

Thanks StarLion, I see your point, what is the recommended method for retrieving all the values?