Connecting two tables |
I have two tables like this
1.jobseets 2.jobsheet_tasks the table jobsheets stores some basic information like customer, date & the jobsheet_tasks only stores the tasks related to each job sheet. on "jobsheets_tasks" table. the id of the "jobsheets" that belongs tasks belongs it is storing for reference purpose here are my tables ![]() there can be one more more tasks under a job sheet. ![]() in order to get the information in both tables i have written the following query. PHP Code: public function get_jobsheets() { and i am showing the data in my view like this. PHP Code: <?php and the output is like this ![]() the query works, but the thing is as you can see in the above image the tasks named 1 & 2 are belongs to a one job sheetete which job sheet id is 61. in the view the tasks belongs to same job sheets shown as separate rows, i want to show the data like this. ![]() tasks of same job sheet one after another. please assist me to achieve this. please provide your solutions in code level
08-16-2016, 06:39 PM
(This post was last modified: 08-17-2016, 06:20 PM by Joel Catantan. Edit Reason: correcting if condition )
I assume that the function in your post is withing your Model - I suggest that you must put a formatting of record within the controller.
public function jobsheets() { $data = array(); $result = $this->your_model->get_jobsheets(); $record_set_count = 0; foreach($result as $index => $row) { // this will check if the next record of foreach (specifically in id) is the same if(@$result[$index+1]->id == $row->id) { $data[$record_set_count]->task .= '<br>'. $row->task; } else { $data[] = $row; $record_set_count++; } } return $data; } Cheers! :)
[Just a programmer]
![]()
(08-16-2016, 06:39 PM)Joel Catantan Wrote: I assume that the function in your post is withing your Model - I suggest that you must put a formatting of record within the controller. Thanks, buddy. i think i have to write this in controller is it. |
Welcome Guest, Not a member yet? Register Sign In |