Welcome Guest, Not a member yet? Register   Sign In
Basic MY_Model question. Need some help
#8

[eluser]victorche[/eluser]
One last question... How can I optimise this:
Code:
public function all_records($table, $where = array(), $field = FALSE, $order = 'ASC')
{
  if (is_array($where) && count($where))
  {
   foreach ($where as $key => $value)
   {
    $this->db->where($key, $value);
   }
  }

  if ($field)
  {
   $this->db->order_by($field, $order);
  }

  $query = $this->db->from($table)
         ->get();

  return $query->result_array();
}
The problem is that I don't always have a where clause. And if I have an order_by clause, then I have to call this function like:
Code:
$posts = $this->model_something->all_records('posts', '', 'author');
Which is ugly and I want to optimise it Smile


Messages In This Thread
Basic MY_Model question. Need some help - by El Forum - 06-02-2012, 02:19 PM
Basic MY_Model question. Need some help - by El Forum - 06-02-2012, 03:06 PM
Basic MY_Model question. Need some help - by El Forum - 06-02-2012, 03:11 PM
Basic MY_Model question. Need some help - by El Forum - 06-02-2012, 03:14 PM
Basic MY_Model question. Need some help - by El Forum - 06-02-2012, 03:18 PM
Basic MY_Model question. Need some help - by El Forum - 06-02-2012, 03:35 PM
Basic MY_Model question. Need some help - by El Forum - 06-02-2012, 04:36 PM
Basic MY_Model question. Need some help - by El Forum - 06-03-2012, 05:23 AM
Basic MY_Model question. Need some help - by El Forum - 06-03-2012, 06:25 AM



Theme © iAndrew 2016 - Forum software by © MyBB