SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2011
    Posts
    46
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Undefined index:

    The usual apologies for being a newb & asking stupid questions... but I'm am using Codeigniter for a basic CRUD app.
    Code PHP:
    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:
    Code PHP:
    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...
    Code PHP:
    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;}
    	}

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,494
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    Just before that if, do a print_r($data['records']) to see what that variable contains.

  3. #3
    SitePoint Enthusiast
    Join Date
    Mar 2011
    Posts
    46
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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_address] => 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 ) )

  4. #4
    SitePoint Enthusiast
    Join Date
    Mar 2011
    Posts
    46
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've updated the controller, making test views to test new code now...


    Code PHP:
    	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);
    		}
     
    	}

  5. #5
    SitePoint Enthusiast
    Join Date
    Mar 2011
    Posts
    46
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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...

  6. #6
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    69 Post(s)
    Tagged
    0 Thread(s)
    foreach($data['records'] as $row) :
    $lvl = $row->qualified_lvl;
    endforeach;

    will only retrieve the last record as $lvl.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  7. #7
    SitePoint Enthusiast
    Join Date
    Mar 2011
    Posts
    46
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks StarLion, I see your point, what is the recommended method for retrieving all the values?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •