[eluser]shinokada[/eluser]
The following code supposed to search and display products which has status is active.
However it shows all the products.
Could anyone tell me what I am missing here?
<b>database</b>
Code:
...
...
CREATE TABLE IF NOT EXISTS `products` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`shortdesc` varchar(255) NOT NULL,
`longdesc` text NOT NULL,
`thumbnail` varchar(255) NOT NULL,
`image` varchar(255) NOT NULL,
`grouping` varchar(16) DEFAULT NULL,
`status` enum('active','inactive') NOT NULL,
`category_id` int(11) NOT NULL,
`featured` enum('true','false') NOT NULL,
`price` float(4,2) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=20 ;
INSERT INTO `products` (`id`, `name`, `shortdesc`, `longdesc`, `thumbnail`, `image`, `grouping`, `status`, `category_id`, `featured`, `price`) VALUES
(1, 'Game 1', 'This is a very good game.', 'What a product! You''ll love the way your kids will play with this game all day long. It''s terrific!', 'images/dummy-thumb.jpg', 'images/dummy-main.jpg', 'fun', 'inactive', 6, '', 19.95),
(2, 'Game 2', 'This is a very good game.', 'What a product! You''ll love the way your kids will play with this game all day long. It''s terrific!', 'images/dummy-thumb.jpg', 'images/dummy-main.jpg', 'fun', 'inactive', 6, '', 19.95),
...
...
<b>models/mproducts.php</b>
Code:
function search($term){
$data = array();
$this->db->select('id,name,shortdesc,thumbnail');
$this->db->like('name',db_clean($term));
$this->db->or_like('shortdesc',db_clean($term));
$this->db->or_like('longdesc',db_clean($term));
$this->db->where('status','active');
$this->db->orderby('name','asc');
$this->db->limit(50);
$Q = $this->db->get('products');
if ($Q->num_rows() > 0){
foreach ($Q->result_array() as $row){
$data[] = $row;
}
}
$Q->free_result();
return $data;
}