Select data from table where date = today - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Select data from table where date = today (/showthread.php?tid=75821) |
Select data from table where date = today - kelapamuda - 03-20-2020 Hello. I want to select data from a table where the date is today,,but still not success yet. One of column is date,,that is where the date is saved, its mysql type data is date. $data['tbl_report'] = $this->db->query("SELECT * FROM tbl_report where sales_id= '".$this->session->id."' ")->result(); That is OK, all data is well output. But i want to show data that is only from today transaction. So I try this : $todaydate =date('Y-m-d'); $data['tbl_report'] = $this->db->query("SELECT * FROM tbl_report where sales_id= '".$this->session->id."' AND date= .$todaydate ")->result(); Its not error, but the table only shows empty result, nothing show up. How to fix that? RE: Select data from table where date = today - jreklund - 03-20-2020 Hi, First off I must start on the fact you have critical security problems with your code. If you are using similar queries in your application you have giving everyone a master key. They have access to all your data in the database. You should use the query bindings if you don't use the Query Builder. https://codeigniter.com/user_guide/database/queries.html#query-bindings https://codeigniter.com/user_guide/database/query_builder.html#selecting-data And for the date part, I think the problem are that you need to have quotes around the date string. You can use last_query to see what it's actually generating, and run it directly inside the database. https://codeigniter.com/user_guide/database/db_driver_reference.html#CI_DB_driver::last_query RE: Select data from table where date = today - kelapamuda - 03-21-2020 $todaydate =date('Y-m-d'); $data['tbl_report'] = $this->db->query("SELECT * FROM tbl_report where sales_id= '".$this->session->id."' AND date= '".$todaydate."')->result(); Yes,it works,, thanks very much RE: Select data from table where date = today - jreklund - 03-21-2020 I can see that you didn't update your code regarding the security issues. Please read the links provided in my last post. It's a critical security hole. |