1

Can anybody help me out, while my solution does not seem to work:

$this->db->where('stock <=','stock_min');
$res = $this->db->get("products")->result();

You see I want to compare the field 'stock' to be less than or equal to 'stock_min'...

Someone?

As requested the table-structure:

    CREATE TABLE IF NOT EXISTS `products` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `sub_of` int(11) DEFAULT NULL,
  `category` int(45) NOT NULL DEFAULT '0',
  `name` varchar(45) NOT NULL DEFAULT '',
  `slug` varchar(250) NOT NULL,
  `number` varchar(45) DEFAULT NULL,
  `description` text NOT NULL,
  `value` decimal(5,0) NOT NULL DEFAULT '0',
  `value_discount` varchar(100) DEFAULT NULL,
  `yell` varchar(100) DEFAULT NULL,
  `display_price` tinyint(1) DEFAULT '0',
  `stock` int(11) NOT NULL DEFAULT '0',
  `stock_min` int(11) NOT NULL DEFAULT '1',
  `warned` tinyint(2) NOT NULL DEFAULT '0',
  `relation` varchar(350) DEFAULT NULL,
  `supplier` varchar(150) DEFAULT NULL,
  `price_in` decimal(10,2) DEFAULT '0.00',
  `price_out` decimal(10,2) DEFAULT '0.00',
  `price_out_btw` decimal(10,2) DEFAULT '0.00',
  `active` smallint(6) DEFAULT '0',
  `display_from` date NOT NULL DEFAULT '0000-00-00',
  `display_till` date NOT NULL DEFAULT '0000-00-00',
  `seen` int(11) NOT NULL DEFAULT '0',
  `info_requested` int(11) NOT NULL DEFAULT '0',
  `inserted` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=322 ;
1
  • post the structure of the table Commented Sep 19, 2012 at 9:46

1 Answer 1

2

Try this:

$this->db->where('stock <= stock_min');

In your code the 'min_stock' is interpreted as the string 'min_stock' not the column. In the future when you have this kind of issues you can call $this->db->last_query(); to see the exact query that is ran against the DB.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.