如何在codeigniter

时间:2017-12-07 06:23:42

标签: mysql sql codeigniter codeigniter-3

我的代码在这里是Sql Query:

$sql ="select * from products where status='1' AND country='5' AND product_price > "50" AND product_price <= "100" order by product_id desc";
$product=$this->db->query($sql)->result_array();

使用海关SQL查看所有产品,但仍未按照说明显示订单。

6 个答案:

答案 0 :(得分:1)

试试这个:

$sql = "SELECT * FROM `products` WHERE `status`=1 AND `country`=5 AND `product_price` > 50 AND `product_price` <= 100 ORDER BY `product_id` DESC";
        $product = $this->db->query($sql)->result_array();

答案 1 :(得分:1)

使用内置的Codeigniter查询构建器更好:

$this->db->select('*');
$this->db->where([
    'status'    => 1,
    'country'   => 5,
    'product_price >' => 50,
    'product_price <=' => 100,
]);
$this->db->order_by('product_id', 'DESC');
$this->db->get('products');
$product = $this->db->result();

答案 2 :(得分:0)

您可以针对您的问题尝试此解决方案:

$query = $this->db->query('select * from products where status='1' AND country='5' AND product_price > "50" AND product_price <= "100" order by product_id desc');
$row_array = $query->result_array();

我跳它会帮助你。

答案 3 :(得分:0)

试试这个

$this->db->from('products');
$this->db->where("status='1' AND country='5' AND product_price > '50' AND product_price <= '100'", null, false);
$this->db->order_by("product_id", "desc");
$query = $this->db->get(); 
return $query->result_array();

答案 4 :(得分:0)

请尝试以下代码:

$this->db->select('products.*');
$this->db->from('products');
$sql="status='1' AND country='5' AND (product_price > '50' AND product_price <= '100')";
$this->db->where($sql, NULL, FALSE)->order_by("product_id", "DESC");

$products_query = $this->db->get();

$products_info_array = array();

$products_info_array = $products_query->result_array();

return $products_info_array;

答案 5 :(得分:0)

你能“描述”输入表吗?如果字段“product_id”是文本(例如: VARCHAR ),那么它将永远不会遵循订单asc / desc ..

抱歉我的英文.. 干得好