[eluser]Devon Lambert[/eluser]
Can anyone tell me how to convert the following to proper CI syntax:
// This would go in the Model //
Code:
function get_categories($where_sql='') {
global $db;
$categories = array();
$query = "SELECT name, type FROM categories ".$where_sql." ORDER BY categories.order ASC";
$result = $db->query($query);
while (($category = mysql_fetch_array($result))) {
$categories[] = $category;
}
return $categories;
}
// This would be the call in the controller //
Code:
$categories = $this->mdl_home->get_categories();
Not really sure what the purpose of the "$db" and "$where_sql" variables are in this function but it appears that the $db variable is being used as a function similar to that of CI's db class?
Sorry still new to all this. :-)
UPDATE: Thought it would help if I gave what I have so far?
Code:
function get_categories() {
$categories = array();
$this->db->select('name,type');
$this->db->order_by('order','asc');
$query = $this->db->get('categories');
//Tried this first
//$result = $this->db->query('$query');
//while ($category = $result->result_array())
// Tried this second
//$result = $query->result_array();
while ($category = $query->result_array())
{
$categories[] = $category;
}
return $categories;
}