Jump to content

Passing data between pages to get a filtered output


KSI
 Share

Go to solution Solved by requinix,

Recommended Posts

Currently I have a table that displays a total count of my data values for each source. I'm getting this value after comparing 2 tables 1 is crm_leads with all my product information and 1 is crm_sources with what sources are the products related to.

Now this is the output:

image.thumb.png.724d7c689ed511a52f2086798a89bf7c.png

Now as you can see the total count is shown under each header next to its source. Now these count values are inside a tags which once clicked go to viewall page. Here basically I want to show the data of the item that I had clicked. So for example, if I clicked the 163 under Hot status, it takes me to the view all page and shows me id, source, enquiry_date for all those under status Hot in a table.

So basically it should detect the data for which source and which status is clicked and then accordingly make a statement like this?

select * from crm_leads where lead_source = '.$source.' and lead_status = '.$status.';

Model Class:

function get_statusreport($fdate='',$tdate='')
    {
        $this->db->select("l.lead_status,crm_sources.title,count(*) as leadnum,l.enquiry_date,l.sub_status");
        $this->db->from($this->table_name." as l");
        if($fdate !='')
            $this->db->where("date(l.added_date) >=",date('Y-m-d',strtotime($fdate)));
        if($tdate !='')
            $this->db->where("date(l.added_date) <=",date('Y-m-d',strtotime($tdate)));
        $this->db->where("lead_status <>",10);
        $this->db->join("crm_sources ","crm_sources.id= l.lead_source","left");
        $this->db->group_by("l.lead_status,crm_sources.title");
        $this->db->order_by("leadnum DESC, crm_sources.title ASC,l.lead_status ASC");
        $query = $this->db->get();
        $results = $query->result_array();
        return $results;
    }

Controller Class(leadstatus holds the view for my current table):

public function leadstatus($slug='')
    {
        $content='';
        $content['groupedleads'] = $this->leads_model->get_statusreport($fdate,$tdate);
        $this->load->view('crm/main',$main);    
        $this->load->view('crm/reports/leadstatus',$content);
    }

public function viewall($slug='')
    {
        $content='';
        $this->load->view('crm/main',$main);    
        $this->load->view('crm/reports/viewall',$content);
    }

View class:

<?php
    $ls_arr = array(1=>'Open',8=>'Hot',2=>'Closed',3=>'Transacted',4=>'Dead'); 
     foreach($groupedleads as $grplead){
        $statuses[] = $status = $ls_arr[$grplead["lead_status"]];
        if($grplead["title"] == NULL || $grplead["title"] == '')
            $grplead["title"] = "Unknown";
        if(isset($grplead["title"]))
            $titles[] = $title = $grplead["title"];
        $leaddata[$status][$title] = $grplead["leadnum"];
    }

    if(count($titles) > 0)
      $titles = array_unique($titles);
    if(count($statuses) > 0)
      $statuses = array_unique($statuses);
    
?>
<table>
<tr">
            <th id="status">Source</th>
             <?php
              if(count($statuses) > 0)
              foreach($statuses as $status){
            ?><th id=<?php echo $status; ?>><?php echo $status; ?></th>
            <?php
              }
            ?>
            <th>Total</th>
          </tr>
<?php
          if(is_array($titles))
            foreach($titles as $title){ 
          ?>
              <tr>
                  <?php 
                    $total = 0;
                    echo "<td>".$title."</td>";
                    foreach ($statuses as $status) {
                        $num = $leaddata[$status][$title];
                        echo "<td><a target='_blank' href='".site_url('reports/viewall')."'>".$num."</a></td>";
                        $total += $num; 
                        $sum[$status] += $num;
                    }
                    echo "<td>".$total."</td>";
                    $grandtotal += $total; 
                   ?>
              </tr>
          <?php } ?>
</table>

 

Link to comment
Share on other sites

  • Solution
5 hours ago, KSI said:

So basically it should detect the data for which source and which status is clicked and then accordingly make a statement like this?

You can't detect what the user clicked on, but you most certainly can have the link tell the page what was clicked on.

Such as by a query string of ?status=Hot.

Grab that status from the query string and incorporate that into the query and page.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.