phpcodeigniteractiverecordwhere-clausesql-like

How i can use multiple like query in CodeIgniter


I want to use multiple queries in my codes with single row. But it doesn't work with multiple. It works only with one query.

Here is my code:

$kuafor = $this->input->post("kuafor");
$donem = $this->input->post("donem");
$ilk_tarih = $this->input->post("ilk_tarih");
$son_tarih = $this->input->post("son_tarih");

$ara = $this->db->select("*")         
       ->or_like(array("kuafor_id"=> $kuafor, "tarih"=> $donem))
       ->or_like(array("tarih >="=> $ilk_tarih, "tarih <="=> $son_tarih))
       ->get("hesaplar");

foreach($ara->result_array() as $row){        
    if(!empty($row["tarih"])){
        echo "var";
    } else {
        echo "yog";
    }
}

EDIT:

Here is my SQL code:

CREATE TABLE `hesaplar` (
  `id` int(11) NOT NULL,
  `kuafor_id` int(11) NOT NULL,
   `tarih` varchar(50) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Tablo döküm verisi `hesaplar`
--

INSERT INTO `hesaplar` (`id`, `kuafor_id`, `tarih`) VALUES
(12, 3, '2018-02-03', 13, 3, '2018-02-04' );

Solution

  • Try to separate each like statement :

    $ara = $this->db->select("*")         
          ->or_like("kuafor_id", $kuafor)
          ->or_like("tarih", $donem)
          ->or_like("tarih >=", $ilk_tarih)
          ->or_like("tarih <=", $son_tarih)
          ->get("hesaplar");