KSI Posted October 28, 2021 Share Posted October 28, 2021 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: <?php foreach($groupedleads as $grplead){ $statuses[] = $status = $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"]; } <table> <?php if(is_array($titles)) foreach($titles as $title){ ?> <tr> <?php 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>"; ?> </tr> </table> Controller Class: public function leadstatus($slug='') { $content['groupedleads'] = $this->leads_model->get_statusreport(); $this->load->view('crm/reports/leadstatus',$content); } 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"; if(isset($grplead["id"])) $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. Quote Link to comment https://forums.phpfreaks.com/topic/314128-looking-up-and-converting-the-ids-for-the-item-clicked-from-a-table/ 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.