skip to Main Content

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);
}

2

Answers


  1. 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"));
    
    Login or Signup to reply.
  2. 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";
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search