CodeIgniter Forums

Full Version: Filtering array values
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have a model :
PHP Code:
           public function biens_vente()
 
           {
 
                       $query $this->db->select('')
 
                       ->from('biens')
 
                       ->where('actif''1')
 
                       ->where('rent','0')
 
                       ->get();

 
                       if($query->num_rows()!==0)
 
                       {
 
                                   return $query->result();
 
                       }
 
                       else
                        
{
 
                                   return FALSE;
 
                       }
 
           
and a Controller :

PHP Code:
public function ventes()
 
           {
 
                       if($this->Biens_model->biens_vente()== FALSE)
 
                       {
 
                             $this->data['erreur'] = "BLABLABLA";
 
                       }
 
                       else
                        
{
 
                             $this->data['biens'] = $this->Biens_model->biens_vente();
 
                       }
 
                       $this->data['title'] = "VENTE";
 
                       $this->render('vente_view');
 
           
In the results I got rows like 'slide1' 'slide2' .... if the row is empty,
I would like to filter the empty rows as I would with an array_filter() before sending to view
How can I do that properly ?
order_by

See the docs
(03-31-2017, 10:36 AM)InsiteFX Wrote: [ -> ]order_by

See the docs

Order_by ? oO

My rows are like :
Code:
id
...
slide1
slide2
slide3
slide4
slide5
slide6
slide7
slide8



In my view I'm using first slide to show it in a list of results so if slide1 is empty I want to get the next slide AND also to make a slideshow on a specific result, I need to filter empty slides...
I don't think "order_by" can do the job but array_filter() can do it
No ?
array_filter() should do it, the manual states that if you do not use a callback that it will
remove the value from the array, which should leave you with a list of valid slides.