EllisLab text mark
Advanced Search
     
Nested foreach loops keep my output from displaying.
Posted: 18 November 2012 01:00 PM   [ Ignore ]
Joined: 2010-09-12
41 posts

I have a query that is outputting the model numbers of some products.  I have a helper in my view that is supposed to go out and get a bunch of specs about each model.  I can’t do this in the same query which is why I’m using the second query in the helper.  At any rate, the code that spits out the models works just fine.

My helper’s query also works by itself.  However, when I call the helper in the middle of my model number foreach loop, it just stops.  It outputs the very first model number and then the page just stops generating.  There isn’t an error message or anything.

Any idea why that would be?

 
Posted: 18 November 2012 03:26 PM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2009-06-19
6267 posts

Your function query is over writing your model query.

You need to save the model query next query for it to work.

I had this same problem when I wrote my delete sessions method, I had to save the query first.

Here is the code for my delete old sessions it is in a MY_Sessions

// --------------------------------------------------------------------

 /**
  * sess_cleanup() - called from sess_destroy()
  *
  * Cleanup expired sessions in the database ci_sessions table.
  * Checks on expired sessions and deletes them from the table.
  *
  * @access private
  * @return void
  */
    
private function _sess_cleanup()
    
{
  
if ($this->sess_use_database != TRUE)
  
{
   
return;
  
}

  $CI 
get_instance();
  
  
$CI->load->database();

  
$query $CI->db->get($this->sess_table_name);
  
$check $query// so queries are not over-written!
  
  
if ($check->num_rows() > 0)
  
{
   
foreach ($check->result() as $row)
   
{
    
// has this session expired?
    
$CI->db->where('session_id'$row->session_id);
    
$CI->db->get($this->sess_table_name);
    
    
$last_activity $row->last_activity;
    
$expire $this->now $this->sess_expiration;
    
    
// seesion has expired so delete it!
    
if ($last_activity $expire)
    
{
     $CI
->db->where('session_id'$row->session_id);
     
$CI->db->delete($this->sess_table_name);
    
}
   }
  }
    } 

 

 Signature 

Ceritfied State of CT Computer Programming Teacher.
Custom Designed Icons, eBook Covers Software Boxes. CD, DVD Etc. New iPhone® Tab Bar Icons and iPhone® Applications Icons.

STOP! Before posting your questions, remember the WWW Golden rule:
What did you try? What did you get? What did you expect to get?

Input -> Controller | Processing -> Model | Output -> View