max
max

Reputation: 3716

delete a row from select result set

so this is my code , it's pretty obvious whats going on

$resultset = $this->m_model->getDetails();

foreach($resultset->result() as $k=>$v )
{
   if($v->condition) 
   unset($resultset->result[$k]) ;
}

obviously

   unset($resultset->result[$k]) ;

doesn't work ... how can i delete from my result set ?

Upvotes: 1

Views: 92

Answers (2)

doitlikejustin
doitlikejustin

Reputation: 6353

Playing off of FaceOfJock's answer, try this:

$resultset = $this->m_model->getDetails();
$result = $resultset->result();

foreach($result as $k=>$v)
{
   if($v->condition) 
   unset($result[$k]);
}

$resultset->result() = (object) $result;

After looking into this more, I don't think what you are looking to do is possible. However, a better solution might be to control this from your model. You can use CI's active records like such:

$this->db->where('some_column !=', 'some_value');

Upvotes: 1

Charaf JRA
Charaf JRA

Reputation: 8334

Try this :

$resultset = $this->m_model->getDetails();
$result=$resultset->result();
foreach( $result as $k=>$v )
{
   if($v->condition) 
   unset($result[$k]) ;
}

Upvotes: 1

Related Questions