I want to use array in WHERE clause. But it doesn't work.
if (count(is_countable($ekkampanyaId) ? $ekkampanyaId : []) > 0) {
$kampanyadizi = implode("','", $ekkampanyaId);
$ekkampanyalar = $Panel_Model->urunkampanyalistele($kampanyadizi, date("Y/m/d"));
MY sql side
public function urunkampanyalistele($array , $tarih) {
$sql = 'SELECT kampanya_ID,kampanya_indirimyuzde FROM flora_kampanya WHERE kampanya_ID IN ("' . $array . '") AND kampanya_aktiflik=1 AND kampanya_baslamatarih<' . $tarih . '<kampanya_bitistarihi';
return $this->db->select($sql);
}
CodePudding user response:
I think you are missing some quotes
if (count(is_countable($ekkampanyaId) ? $ekkampanyaId : []) > 0) {
$kampanyadizi = ",".implode("','", $ekkampanyaId)."'";
$ekkampanyalar = $Panel_Model->urunkampanyalistele($kampanyadizi, date("Y/m/d"));
CodePudding user response:
We need to be familiar when to use single and double quotes and escape characters.
Query string should be:
$sql = "SELECT kampanya_ID,kampanya_indirimyuzde FROM flora_kampanya WHERE kampanya_ID IN ('" . $array . "') AND kampanya_aktiflik=1 AND kampanya_baslamatarih<'" . $tarih . "'<kampanya_bitistarihi";