简体   繁体   中英

How to use if statement inside the helper in codeigniter

How do I use if statement inside the helper. I have pasted the function from the helper which is not working but I can't find the problem.

helper.php

function get_recipients($data)
   {
      $CI =& get_instance();
      $CI->load->database();

      $CI->db->where('company_id', $data["company_id"]);

      if ($data["database_name"] != '' || $data["database_name"] != 'all') {
        $CI->db->where('database_name', $data["database_name"]);
      }

      if ($data["province"] != '' || $data["province"] != 'all') {
        $CI->db->where('province', $data["province"]);
      }

      if ($data["district"] != '' || $data["district"] != 'all') {
        $CI->db->where('district', $data["district"]);
      }

      if ($data["ward"] != '' || $data["ward"] != '0' || $data["ward"] != 'all') {
        $CI->db->where('ward', $data["ward"]);
      }

      if ($data["farm"] != '' || $data["farm"] != 'all') {
        $CI->db->where('farming_type', $data["farm"]);
      }

      if ($data["commodity"] != '' || $data["commodity"] != 'all') {
        $CI->db->where('commodity', $data["commodity"]);
      }

      $query = $CI->db->get('addressbook');

      if($query->num_rows() >= 0){
         return $query->num_rows();
        }
        else {
          return false;
        }

   }

The values of database, province, district, ward, farm and commodity are either empty, string(all) or any other different string. The WHERE query is to be executed when the conditions match.

The variable $data is coming with the correct data but the WHERE queries are being executed no matter the values of $data

try like this...

function get_recipients($response)
   {
      $data  = (array)$response;//converts in to array
      $CI =& get_instance();
      $CI->load->database();
      $CI->db->where('company_id', $data["company_id"]);

          if ($data["database_name"] != '' || $data["database_name"] != 'all') {
            $CI->db->where('database_name', $data["database_name"]);
          }

         //more code

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM