Question

I am trying to pass parameters from Yii MVC to a CodeIgniter model method and search for results between a time interval;

The created property has values like 26/2/2014;

Will the query execute and concat the two where clauses regarding the field created with get_where clause?

Or it will execute only the get_where clause?

I can't see the result, but the created value is being passed;

the created field is stored as a timestamp value in the db and I use a date picker to select the day/month/year, then I pass the value thru the api and then I create the 24 hour time interval

and this is where i got stuck;

ps: this is a good example when using EActiveResource instead of ActiveRecord and passing data thru a api built using codeIgniter

public function findAll($params) {
        if (!empty($params)) {
            if (isset($params['created'])) {
                $e = explode('/', $params['created']);
                $month = $e[1];
                $day = $e[0];
                $year = $e[2];
                $start = mktime(0, 0, 0, $month, $day, $year);
                $end = mktime(23, 59, 59, $month, $day, $year);
                $this->db->where('created >', $start);
                $this->db->where('created <', $end);
            }
            $query = $this->db->get_where($this->_table, $params);
        } else {
            $query = $this->db->get($this->_table);
        }
        $ret = $query->result_array();
        foreach ($ret as $key => $value) {
            $ret[$key]['order_id'] = $value['id'];
        }
        return (isset($ret) && !empty($ret)) ? $ret : false;
    }

I tryed to set the value of $params['created'] within yii and pass it to codeIgniter just to make sure I pass the if;

In the codeIgniter model I have:

    if (!empty($params)) {
        if (isset($params['created'])) {
            $this->db->where('created >=', 1393246473);
            $this->db->where('created <=', 1393404935);
        }
        $query = $this->db->get_where($this->_table, $params);
    } else {
        $query = $this->db->get($this->_table);
    }
    $ret = $query->result_array();

still no data as result;

any ideas?

No correct solution

OTHER TIPS

try this

public function findAll($params) {
            if (!empty($params)) {
                if (isset($params['created'])) {
                    $e = explode('/', $params['created']);
                    $month = $e[1];
                    $day = $e[0];
                    $year = $e[2];
                    $start = mktime(0, 0, 0, $month, $day, $year);
                    $end = mktime(23, 59, 59, $month, $day, $year);
                    $this->db->where(array('created >'=> $start, 'created <'=> $end));

                }
                $query = $this->db->get($this->_table);
            } else {
                $query = $this->db->get($this->_table);
            }
            $ret = $query->result_array();
            foreach ($ret as $key => $value) {
                $ret[$key]['order_id'] = $value['id'];
            }
            return (isset($ret) && !empty($ret)) ? $ret : false;
        }

if you want to use get_where then pass all condition in array

$this->db->get_where('mytable', array('id' => $id, 'created' => $cre), $limit, $offset);

also you can write a sql query like:-

$sql = "SELECT * FROM example WHERE payment_status = '0' AND intial_pay_status = '1'";

        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
          foreach ($query->result() as $row) {
            //echo '<pre>'; print_r($row); 
                  }
                }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top