CodeIgniter Forums
my "sizeof" doesn't work - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: my "sizeof" doesn't work (/thread-40848.html)



my "sizeof" doesn't work - El Forum - 04-20-2011

[eluser]rikes_denis[/eluser]
i tried to get an array data of my checkbox, and when i use sizeof to make limit in my loop, i think it might not work properly
this is my code :
model
Code:
$checkBox = $this->input->post('checked');
      print_r($checkBox);
      for($i=0; $i<sizeof($checkBox); $i++){
    //    $this->db->order_by('id_js','asc');
      $this->db->where('id_edu',$checkBox[$i]);
      return $this->db->get($this->tbl);
    }



controller

Code:
function preview()
    {
        $items = $this->educationmodel->preview()->result();
        $i = 0;
        foreach($items as $item){
            $this->table->add_row(++$i, $item->id_edu,$item->edu_per1, $item->edu_per2, $item->institution, $item->qual, $item->gpa);
            }
            $data['table'] = $this->table->generate();
            $data['dynamiccontent'] = 'coba_preview';
            $this->load->view('templates/template', $data);
                
    }

i dunno if sizeof can work properly in CI or not, can someone help?
thanx b4


my "sizeof" doesn't work - El Forum - 04-20-2011

[eluser]CroNiX[/eluser]
I think its fine. It looks like your problem is your return is within your loop, so it will only go through the loop once and return no matter how many elements are in the $checkBox array.

As a side note, foreach() is faster than using manual iteration...
Code:
$checkBox = $this->input->post('checked');

foreach($checkBox as $i => $value)
{
      $this->db->where('id_edu',$checkBox[$i]);  
}
//now that you have built up the where statements, execute and return the whole query...
return $this->db->get($this->tbl);



my "sizeof" doesn't work - El Forum - 04-20-2011

[eluser]rikes_denis[/eluser]
but if i put the return outside the loop, i got nothing to return to the controller, undifined data table.
what i try to do is to show the data that i already checked before filtering by id and the data i retrieve from database. this data from database that i try to return
is there something i missing or i got the wrong logic?
please help

sorry my english and thanx for the respon b4


my "sizeof" doesn't work - El Forum - 04-20-2011

[eluser]danmontgomery[/eluser]
because you're using where(), so your query looks something like "SELECT * FROM some_table WHERE id_edu = 1 AND id_edu = 2" etc... I'm guessing that id_edu is a primary key, so you're never going to return any results. You want to use either or_where() or where_in(). Something like:

Code:
$checkBox = $this->input->post('checked');
return $this->db->where_in('id_edu', $checkBox)->get($this->tbl);



my "sizeof" doesn't work - El Forum - 04-20-2011

[eluser]rikes_denis[/eluser]
great...
it works!
i need to much..much..much learn and practice
thanks nocturn, to share your knowledge to me
thank you so much
Big Grin