I need to get the the subcategories of its categories in codeigniter. I am stuck at passing category id to the my model method
my code is below :
this is my view : index.php
<ul class="list-inline">
<?php
if($category->num_rows() > 0)
{
foreach ($category->result() as $row)
{
?>
<li><a href="<?php echo base_url();?>main/getsubcategory<?php $row->id; ?>"><img class="img-responsive center-block" width="80px" src="<?php echo base_url(); ?>assets/admin/uploads/category/<?php echo $row->cat_home_image; ?>" alt="icon" title="icon" class="img-responsive" /><p style="font-size:16px;"><?php echo $row->category_description; ?> </p></a></li>
<?php
}
}
?>
</ul>
this is my controller : Main.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Main extends CI_Controller {
public function index()
{
$this->load->model("category_model");
$data["category"] = $this->category_model->fetch_category();
$this->load->model("ads_model");
$data["ads"] = $this->ads_model->fetch_home_ads();
$this->load->view('index',$data);
//$this->load->view('category');
}
public function getsubcategory()
{
$this->load->model("category_model");
$data["subcategory"] = $this->category_model->fetch_subcategory();
$this->load->view('category',$data);
}
}
this is my Model : category_model.php
<?php
class Category_model extends CI_Model
{
function fetch_category()
{
$query = $this->db->query("SELECT * FROM category AS c INNER JOIN category_language AS cl ON c.id=cl.category_id where parent_id IS NULL && lang_id='1' && c.id!='4' ORDER BY category_description");
return $query;
}
function fetch_subcategory()
{
$subcat = $this->db->query("SELECT * FROM category AS c INNER JOIN category_language AS cl ON c.id=cl.category_id where parent_id='1' && lang_id='1' ORDER BY category_description");
return $subcat;
}
}
?>
How to pass the category id to model to get the appropriate subcatory of category_id