我被困在代码点火器中实现简单where子句。我拥有的是这个
public function get_low_stock()
{
$this->db->select('*');
$this->db->where('productQty <=' , '10'); //line where the problem is
$this->db->from('products');
$query = $this->db->get();
return $query->result();
}我需要从minQty colum中选择值'10‘,但无法实现这一点。这样,一旦更改了数据库中的minQty,就会自动获得正确的低质量。请看一下我的桌子结构。
CREATE TABLE IF NOT EXISTS `products` (
`productid` int(11) NOT NULL,
`productname` varchar(30) NOT NULL,
`catid` int(11) NOT NULL,
`productqty` int(11) NOT NULL,
`buyprice` int(11) NOT NULL,
`saleprice` int(11) NOT NULL,
`minqty` int(11) NOT NULL,
`maxqty` int(11) NOT NULL,
`alertlevel` int(11) NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=18 DEFAULT CHARSET=latin1;
--
-- Dumping data for table `products`
--
INSERT INTO `products` (`productid`, `productname`, `catid`, `productqty`, `buyprice`, `saleprice`, `minqty`, `maxqty`, `alertlevel`) VALUES
(1, '2.6 china touch', 1, 9, 2500, 5000, 10, 100, 15),
(4, '2.9 china touch', 1, 10, 2500, 5000, 10, 100, 15),
(5, '3.0 small cable', 1, 5, 2500, 5000, 10, 100, 15);发布于 2015-07-15 19:57:20
你可以用两种方式。
1#
$query=$this->db->query('SELECT * FROM `products` where productqty <= minqty');
return $query->result();2#
$this->db->select('*');
$this->db->where('productqty <=minqty',null,false);
//or use this way
//$this->db->where('productqty <=minqty');
$this->db->from('products');
$query = $this->db->get();
return $query->result();注释您使用了productQty,但是您的数据库列名是productqty,.It可以work.But使用正确的。
发布于 2015-07-15 17:54:47
试试这个:
$where = '(productQty <= minqty)';
$this->db->where($where);正如您所提到的,minqty在代码中是动态的。
$this->db->where('productQty <= minqty');发布于 2015-07-16 14:06:26
如果你看了这两种答案,你就会发现你的答案完全一样,只是略有变化。
https://stackoverflow.com/questions/31437528
复制相似问题