Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用API Rest的URL的日期过滤器-Codeigniter_Php_Mysql_Api_Codeigniter - Fatal编程技术网

Php 使用API Rest的URL的日期过滤器-Codeigniter

Php 使用API Rest的URL的日期过滤器-Codeigniter,php,mysql,api,codeigniter,Php,Mysql,Api,Codeigniter,我想在一个日期间隔内显示所有订单,该日期间隔通过URL:localhost/ws/v1/orders/2019-01-01/2019-01-31发送 但我的结果总是我的第一个订单,无论我插入什么日期。如果我键入的URL没有两个日期,则不返回任何内容 控制器 public function getOrders_get() { header("Access-Control-Allow-Origin: *"); // Load Authorization Token Library

我想在一个日期间隔内显示所有订单,该日期间隔通过URL:localhost/ws/v1/orders/2019-01-01/2019-01-31发送

但我的结果总是我的第一个订单,无论我插入什么日期。如果我键入的URL没有两个日期,则不返回任何内容

控制器

public function getOrders_get() {
    header("Access-Control-Allow-Origin: *");

    // Load Authorization Token Library
    $this->load->library('Authorization_Token');

    $fromDate =  $this->uri->segment(3);
    $toDate =  $this->uri->segment(4);

    /**
     * User Token Validation
     */
    $is_valid_token = $this->authorization_token->validateToken();

    if (!empty($is_valid_token) AND $is_valid_token['status'] === TRUE)
    {
      if (empty($id)){
          $data = $this->db->get_where("`ga845_pedidos_view` WHERE `data` BETWEEN date('$fromDate') AND date('$toDate')")->row_array();
      }else{
          $data = $this->db->get_where("ga845_pedidos_view", ['id' => $id])->row_array();
      }

      $this->response($data, REST_Controller::HTTP_OK);

    } else {
        $this->response(['status' => FALSE, 'message' => $is_valid_token['message'] ], REST_Controller::HTTP_NOT_FOUND);
    }
}
返回:

 "id": "160",
  "data": "2017-01-25 12:33:24",
  "status": "3",
  ...

我用这种方法解决问题

我的URL:localhost/ws/v1/2019-01-01/2019-01-10 1-本地主机;第2-ws;3rt-v1;4th-2019-01-01;第5次-2019-01-10

$fromDate =  $this->uri->segment(4); // 4 step of URL
$toDate =  $this->uri->segment(5);   // 5 step of URL

$this->db->where('order_date >=', $fromDate);
$this->db->where('order_date <=', $toDate);
$data = $this->db->get("order_table")->result();
$fromDate=$this->uri->segment(4);//URL的4个步骤
$toDate=$this->uri->segment(5);//URL的5个步骤
$this->db->where('order\u date>=',$fromDate);

$this->db->where('order_date您必须在strotime()中转换日期,并进行如下检查

        $from = strtotime($fromDate);
        $to = strtotime(toDate);
你的问题是

     BETWEEN {$from} AND {$to}

只需检查正在生成的查询并调试您的SQL查询。通过
$this->db->last_query()
获取您的上一个查询并共享。