Welcome Guest, Not a member yet? Register   Sign In
categories display problem show all categories
#8

(01-16-2015, 03:40 AM)Rufnex Wrote: You have to add a where clause to your model like


PHP Code:
public function get_categories($category_name false$order_by null$sort 'DESC'$limit null$offset 0) {
 
       $this->db->select('a.*, c.name as category_name');
 
       $this->db->from('articles as a');
 
       $this->db->join('categories AS c''a.category_id = c.id ','LEFT');
 if (
$category_name)
 {
 
$this->db->where('categories.name'$category_name);
 }
 
       if($limit != null) {
 
           $this->db->limit($limit$offset);
 
       }
 
       if($order_by != null) {
 
           $this->db->order_by($order_by$sort);
 
       }
 
       $query $this->db->get();
 
       return $query->result();


Or you check the where with the category id ..

This Give Error
Code:
A Database Error Occurred

Error Number: 1054

Unknown column 'categories.name' in 'where clause'

SELECT `a`.*, `c`.`name` as category_name FROM (`articles` as a) LEFT JOIN `categories` AS c ON `a`.`category_id` = `c`.`id` WHERE `categories`.`name` = 'id' ORDER BY `DESC` DESC

Filename: /var/www/html/page/models/article_model.php

Line Number: 88
Reply


Messages In This Thread
RE: categories display problem show all categories - by asifagaria - 01-16-2015, 08:15 AM



Theme © iAndrew 2016 - Forum software by © MyBB