Jump to content

Looking up and converting the ids for the item clicked from a table


Recommended Posts

In my database, I have a id and title column where each title has a specific id, for example 1 is IT, 2 is Sales, etc. Now to show this in a table format I'm using the following code:

View class:

     foreach($groupedleads as $grplead){
        $statuses[] = $status = $grplead["lead_status"];
        if($grplead["title"] == NULL || $grplead["title"] == '')
            $grplead["title"] = "Unknown";
            $titles[] = $title = $grplead["title"];
        $leaddata[$status][$title] = $grplead["leadnum"];
            foreach($titles as $title){ 
                    echo "<td>".$title."</td>";
                    foreach ($statuses as $status) {
                        $num = $leaddata[$status][$title];
                        echo "<td><a target='_blank' href='" . site_url('reports/viewall?source=' . $title) . "'>".$num."</a></td>";

Controller Class:

public function leadstatus($slug='')
        $content['groupedleads'] = $this->leads_model->get_statusreport();

Model Class:

function get_statusreport($fdate='',$tdate='')
        $this->db->select("l.lead_status,crm_sources.title,crm_sources.id,count(*) as leadnum");
        $this->db->from($this->table_name." as l");
        $this->db->join("crm_sources ","crm_sources.id= l.lead_source","left");
        $query = $this->db->get();
        $results = $query->result_array();
        return $results;

Now I can see the titles for each of these in my table, but as of now these items under each title are clickable and lead to a different page. I use this code to get that href='" . site_url('reports/viewall?source='.$title). Now I actually want the id to be passed instead of the string value of title. So basically it has to look up from the database for the id of the particular items title that was clicked.

When I write the following code for the first forloop, it returns the ids for all the items where currently the titles are residing:

     foreach($groupedleads as $grplead){
        $statuses[] = $status = $grplead["lead_status"];
        if($grplead["id"] == NULL || $grplead["id"] == '')
            $grplead["id"] = "Unknown";
            $titles[] = $id= $grplead["id"];
        $leaddata[$status][$id] = $grplead["leadnum"];

But I want the display to show it as title only, but the link should be replaced with the id instead of the title which it's currently showing.

Link to comment
Share on other sites

This thread is more than a year old. Are you sure you have something important to add to it?

Join the conversation

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

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.


  • 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.