Rizky Dwiananto
Rizky Dwiananto

Reputation: 19

invalid argument supplied for foreach () for code "DateTime::createFromFormat"?

I set it in codeigniter so that the timestamp is in the database with the format (yyyy-mm-dd hh: ii: ss) to (yyyy-mm-dd)


    function login($patient_ext_id,$birth_dttm) {
            $this->db->select('xocp_ehr_patient.patient_ext_id, xocp_persons.person_nm, xocp_persons.birthplace, xocp_persons.birth_dttm, xocp_persons.status_cd, xocp_persons.race_nm');
            $this->db->from('xocp_ehr_patient');
            $this->db->join('xocp_persons', 'xocp_ehr_patient.person_id = xocp_persons.person_id');
            /*$this->db->join("xocp_persons","xocp_persons.person_id = xocp_ehr_patient.patient_ext_id","left");*/
            $this->db->where('xocp_ehr_patient.patient_ext_id', $patient_ext_id);
            $tgl = $this->db->select(DateTime::createFromFormat('Y-m-d','xocp_persons.birth_dttm'));
            $this->db->where($tgl, $birth_dttm);
            /*$query =  $this->db->get('xocp_persons');*/
            $query =  $this->db->get('');
            return $query->num_rows();
        }

code invalid in file database/DB_query_build.php

public function select($select = '*', $escape = NULL)
    {
        if (is_string($select))
        {
            $select = explode(',', $select);
        }

        // If the escape value was not set, we will base it on the global setting
        is_bool($escape) OR $escape = $this->_protect_identifiers;

        foreach ($select as $val)
        {
            $val = trim($val);

            if ($val !== '')
            {
                $this->qb_select[] = $val;
                $this->qb_no_escape[] = $escape;

                if ($this->qb_caching === TRUE)
                {
                    $this->qb_cache_select[] = $val;
                    $this->qb_cache_exists[] = 'select';
                    $this->qb_cache_no_escape[] = $escape;
                }
            }
        }

        return $this;
    }

Severity: Warning Message : Invalid argument supplied for foreach() Filename: database/DB_query_builder.php

Line Number: 294

Upvotes: 1

Views: 121

Answers (2)

Mohammedshafeek C S
Mohammedshafeek C S

Reputation: 1943

Your query was wrong.You can replace login function as following.

function login($patient_ext_id,$birth_dttm) {
    $this->db->select('xocp_ehr_patient.patient_ext_id, xocp_persons.person_nm, xocp_persons.birthplace, xocp_persons.birth_dttm, xocp_persons.status_cd, xocp_persons.race_nm');
    $this->db->from('xocp_ehr_patient');
    $this->db->join('xocp_persons', 'xocp_ehr_patient.person_id = xocp_persons.person_id');
    /*$this->db->join("xocp_persons","xocp_persons.person_id = xocp_ehr_patient.patient_ext_id","left");*/
    $this->db->where('xocp_ehr_patient.patient_ext_id', $patient_ext_id);
    $this->db->having("DATE_FORMAT( xocp_persons.birth_dttm, '%Y-%m-%d') = '$birth_dttm'", "",false);
    /*$query =  $this->db->get('xocp_persons');*/
    $query =  $this->db->get('');
    return $query->num_rows();
}

Upvotes: 0

PHP Geek
PHP Geek

Reputation: 4033

print $select. is there getting data an array

    if(is_array($select)){
 foreach ($select as $val)
        {
     $val = trim($val);
      if ($val !== '')
        {
        $this->qb_select[] = $val;
        $this->qb_no_escape[] = $escape;
      if ($this->qb_caching === TRUE)
     {
        $this->qb_cache_select[] = $val;
        $this->qb_cache_exists[] = 'select';
        $this->qb_cache_no_escape[] = $escape;
            }
           }
          }
}

Upvotes: 1

Related Questions