phpsqlmysqlcodeigniterquoting

SQL string with mix of single quotes and double quotes not ordering properly in CodeIgniter


My code is here 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();

It returns all products by using customs SQL but still not showing order by desc.


Solution

  • Try this:

    $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();