PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, January 23, 2022

[FIXED] Data range in URL Routes Codeigniter

 January 23, 2022     api, codeigniter, mysql, php     No comments   

Issue

I have an API that's working fine without this data range in URL, but now I need to set to better search, as this example, after /orders.

E.g.: http://localhost/ws/v1/orders?fromDate=2019-01-01&toDate=2019-12-31

Controller:

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

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

    /**
     * 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("order_view")->result();
      }else{
          $data = $this->db->get_where("order_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);
    }
    }

Solution

You can add a between to you sql.

$from_date = $_GET['fromDate'];
$to_date = $_GET['toDate'];
...
$this->db->where("date between $from_date and $to_date");


Answered By - LF00
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing