Welcome Guest, Not a member yet? Register   Sign In
Nested foreach loops keep my output from displaying.
#1

[eluser]ChrisF79[/eluser]
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?
#2

[eluser]InsiteFX[/eluser]
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
Code:
// --------------------------------------------------------------------

/**
  * 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);
    }
   }
  }
    }




Theme © iAndrew 2016 - Forum software by © MyBB