JJM50 Posted October 12, 2021 Share Posted October 12, 2021 (edited) I have a table in PHP that displays the status count report in a particular date range. I have created the code so that it fetches the 2 inputs and displays my output according to those 2 values. So initially the value it shows is 0 before the date filter, but I want it so that the initial value that it shows is the total count from day 0 till today. Currently this is my model class: function get_listingstatus($fdate,$tdate){ $this->db->select("SUM(CASE WHEN status = 'Active' THEN 1 END) AS active"); $this->db->from('logs'); $this->db->where('cast(logtime as date) BETWEEN "' . $fdate . '" AND "' . $tdate . '"'); $results = $this->db->get(); return $results; } Controller Class: public function totallistings($slug='') { $fdate = $this->input->post("fdate"); $content['tdate'] = $tdate = $this->input->post("tdate"); if(isset($fdate)){ $content['fdate'] =$fdate; }else{ $content['fdate'] = ''; } if(isset($tdate)){ $content['tdate'] =$tdate; }else{ $content['tdate'] =''; } $content['data_sum'] = $this->leads_model->get_listingstatus($fdate,$tdate)->result(); $main['content']=$this->load->view('crm/reports/totallistings',$content,true); $this->load->view('crm/main',$main); } And my View class is like so: <?php if(isset($data_sum) && count($data_sum) > 0) { foreach($data_sum as $row ){ $active = $row->active ? $row->active : 0; ?> <tr> <td><?= $active ?></td> </tr> <?php } } else { ?> <tr> <td>No Data Found</td> </tr> <?php } ?> Here my initial value is 0 and when I make the search filter it returns the output within a date range, But I want to change this initial value to have the full count shown. Edited October 12, 2021 by JJM50 Quote Link to comment https://forums.phpfreaks.com/topic/313956-showing-all-data-initially-before-a-filter-in-codeigniter/ Share on other sites More sharing options...
requinix Posted October 12, 2021 Share Posted October 12, 2021 if(isset($fdate)){ $content['fdate'] =$fdate; }else{ $content['fdate'] = ''; } if(isset($tdate)){ $content['tdate'] =$tdate; }else{ $content['tdate'] =''; } That looks relevant. Have you tried changing those two empty strings to be something else? Quote Link to comment https://forums.phpfreaks.com/topic/313956-showing-all-data-initially-before-a-filter-in-codeigniter/#findComment-1590933 Share on other sites More sharing options...
JJM50 Posted October 12, 2021 Author Share Posted October 12, 2021 (edited) 28 minutes ago, requinix said: if(isset($fdate)){ $content['fdate'] =$fdate; }else{ $content['fdate'] = ''; } if(isset($tdate)){ $content['tdate'] =$tdate; }else{ $content['tdate'] =''; } That looks relevant. Have you tried changing those two empty strings to be something else? So if I want fdate to get my day 0 and tdate to get todays date, how can I edit it to show those variables? Edited October 12, 2021 by JJM50 Quote Link to comment https://forums.phpfreaks.com/topic/313956-showing-all-data-initially-before-a-filter-in-codeigniter/#findComment-1590935 Share on other sites More sharing options...
requinix Posted October 12, 2021 Share Posted October 12, 2021 6 minutes ago, JJM50 said: So if I want fdate to get my day 0 and tdate to get todays date, how can I edit it to show those variables? I don't know what "day 0" is, but you can get a string representing today's date with, surprisingly enough, the date() function. Quote Link to comment https://forums.phpfreaks.com/topic/313956-showing-all-data-initially-before-a-filter-in-codeigniter/#findComment-1590936 Share on other sites More sharing options...
JJM50 Posted October 12, 2021 Author Share Posted October 12, 2021 (edited) 30 minutes ago, requinix said: I don't know what "day 0" is, but you can get a string representing today's date with, surprisingly enough, the date() function. Okay so I tried this and it's not the solution, but I've found out that I've to update my else statement with an additional model. So what I've done now is added an extra model removing the where statement: function get_listingstatus_total(){ $this->db->select("SUM(CASE WHEN status = 'Active' THEN 1 END) AS active"); $this->db->from('logs'); $results = $this->db->get(); return $results; } and added it in my controller class: $content['data_total'] = $this->leads_model->get_listingstatus_total()->result(); And put the following in my view class: <?php if(isset($data_sum) && count($data_sum) > 0) { foreach($data_sum as $row ){ $active = $row->active ? $row->active : 0; ?> <tr> <td><?= $active ?></td> </tr> <?php } } else { ?> <?php foreach($data_total as $row ){ $active = $row->active ? $row->active : 0; ?> <tr> <td><?= $active ?></td> </tr> <?php } ?> But unfortunately it still returns 0, but I'm sure this is the solution I've to use. When I put the $data_total instead of $data_sum in if statement it gives correct output, but like this it gives wrong Edited October 12, 2021 by JJM50 Quote Link to comment https://forums.phpfreaks.com/topic/313956-showing-all-data-initially-before-a-filter-in-codeigniter/#findComment-1590937 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.