A good example of codeigniter MVC? What is the difference between this two way and Which one is best? What do you suggest?

1.
Use of query (db) directly in CI_Controller. as:

$id = $this-&gt;input-&gt;post('id');
$query = $this-&gt;db-&gt;get_where('table1', array('id' =&gt; $id))-&gt;row();
         $this-&gt;db-&gt;get_where('table2', array('idre' =&gt; $query-&gt;idre));


Or

2.
Use of query (db) in CI_Model and call it in CI_Controller. as:

CI_Model:

function GetWhere($table,$where){
    return $this-&gt;db-&gt;get_where($table, $where);
}


CI_Controller:

$id = $this-&gt;input-&gt;post('id');
$query = $this-&gt;model_name-&gt;GetWhere('table1', array('id' =&gt; $id))-&gt;row();
         $this-&gt;model_name-&gt;GetWhere('table2', array('idre' =&gt; $query-&gt;idre));


UPDATE:

3. 
I use the following code true in model as mvc?

$id = $this-&gt;input-&gt;post('checked');
        foreach ($id as $val) {
            $query_check = $this-&gt;db-&gt;get_where(table3, array('id'=&gt;$val));
            $row = $query_check-&gt;row();
            if($query_check-&gt;num_rows() &gt; 0 || $row-&gt;id != $this-&gt;session-&gt;userdata('id')){
                foreach ($query_check-&gt;result() as $value) {
                    $id_relation = $value-&gt;id_relation;
                    $this-&gt;db-&gt;where('idre', $idre)-&gt;delete(array(table3, 'table4'));
                }
            }
        }


Whether this is a good example of mvc? How can fix 2 example above for good mvc?
What is the difference between this two way and Which one is best? What do you suggest?


The difference is that you seperate the concerns in the second example. This means that you can change from database type (e.g. a SQL database, a XML file, an array, ect.) without changing to much code. In fact, you only create a new Model and you are ready!


  Whether this is a good example of mvc? How can fix 2 example above for good mvc?


I think you mean that you want to know if this is correct MVC and, if not, how to change it. It is better to put all those logic (except the first line) inside a Model and call that specific method inside your controller. I have used CI once, so I can't help you with code examples...