首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >具有两个字段值的Codeigniter活动记录where子句

具有两个字段值的Codeigniter活动记录where子句
EN

Stack Overflow用户
提问于 2015-07-15 17:48:08
回答 3查看 912关注 0票数 0

我被困在代码点火器中实现简单where子句。我拥有的是这个

代码语言:javascript
复制
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,就会自动获得正确的低质量。请看一下我的桌子结构。

代码语言:javascript
复制
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);
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2015-07-15 19:57:20

你可以用两种方式。

1#

代码语言:javascript
复制
$query=$this->db->query('SELECT * FROM `products` where productqty <= minqty');
return $query->result();

2#

代码语言:javascript
复制
$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使用正确的。

票数 0
EN

Stack Overflow用户

发布于 2015-07-15 17:54:47

试试这个:

代码语言:javascript
复制
$where = '(productQty <= minqty)';

$this->db->where($where);

正如您所提到的,minqty在代码中是动态的。

代码语言:javascript
复制
$this->db->where('productQty <= minqty');
票数 0
EN

Stack Overflow用户

发布于 2015-07-16 14:06:26

如果你看了这两种答案,你就会发现你的答案完全一样,只是略有变化。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31437528

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档