[eluser]CodeIgniterNoob[/eluser]
Hello,
I need to write a weird query.
I have two tables, "categories", and "sub_categories",
"categories" fields are
category_id category_name category_level category_status parent_id parent_name category_sortorder
and "sub_categories" fields are
sub_category_id sub_category_name sub_category_status sub_category_sortorder category_id
I need to pull out all the sub's based on the sub_category_name(this is what Im passing to the query). So I need to pull out all the other sub_categories which belong to the main category by category_id.
Can SQL even do that?
Code:
function returnSubCategories($catname=NULL)
{
$this->db->select('*');
$this->db->from('sub_categories','categories');
$this->db->where('sub_category_name', $catname);
$this->db->join('categories', 'categories.category_id = sub_categories.category_id');
$Q = $this->db->get();
if ($Q->num_rows() > 0)
{
return $Q->result_array();
}
$Q->free_result();
}