To Removing an item from object in a loop
$query = $this->db->query("YOUR QUERY");
$rows = $query->result();
foreach ($rows as $key => $row)
{
if($row->parent_id == 1){
unset($rows[$key]);
// code here to delete current record
}
}
print_r($rows) // remove row with parent_id = 1
See more @ Removing an item from object in a loop
You could also change your select statement to get all records where parent_id not eq 1 (or other 'where' logic to filter the rows... see example and link below)
$this->db->get('mytable')
$this->db->where('parent_id !=', 1);
or
//get all except parent id 1,4 or 7
$parent_ids = array(1, 4, 7);
$this->db->where_not_in('parent_id', $parent_ids);
To delete records from the database as your previous question title suggested (Delete current record with foreach in CodeIgniter)
You can do this using sql query without using any php logic by write the condition in sql ... see more at http://codeigniter.com/user_guide/database/active_record.html
example
//delete record where parent_id = 1
$this->db->delete('mytable', array('parent_id' => 1));
or
//delete record where parent_id = 1 or 5 or 8
$names = array(1, 5, 8);
$this->db->where_in('parent_id', $names);
$this->db->delete('mytable');
or
//delete record where parent_id = 1
$this->db->where('parent_id', 1);
$this->db->delete('mytable');
or
//delete all record where parent_id not eq 1
$this->db->where('parent_id !=', 1);
//delete all record where parent_id less than 10
$this->db->where('parent_id <', 10);