Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Just for example, you are looping around <code>foreach($projects_query as $row)</code> and you call <code>get_projects()</code> for this. And in the loop you are calling <code>get_team_name($team_id)</code> with the<code>team_id</code>, right? Now, just change your model function <code>get_projects()</code> a little to get the <code>team name</code> at once:</p> <pre><code>function get_projects() { $this-&gt;db-&gt;select('*'); $this-&gt;db-&gt;from('tbl_task'); $this-&gt;db-&gt;where('intInside','0'); $query = $this-&gt;db-&gt;get(); //return $query-&gt;result(); //instead of returning loop here and fetch the team name $data = $query-&gt;result_array(); if( is_array( $data ) &amp;&amp; count( $data ) &gt; 0 ){ foreach( $data as $key =&gt; $each ){ $data[$key]['team_name'] = $this-&gt;get_team_name( $each['intTeamID'] ); //fetching of the teamname and saving in the array } } return $data; //Now return the data array. :D } </code></pre> <p>In view:</p> <pre><code>//$query_team_user_id = $this-&gt;admin_in_out_model-&gt;get_user_team_task_query($row2-&gt;intTaskID); #you dont need it now if you make a 2d array foreach($row['team_name'] as $row_teamid){ #changed $query_team_user_id to $row['team_name'] as this will now represent an array //inside the loop } </code></pre> <p>Similarly, you need to fetch all the relevant data that you need to print in your page in the model itself and no need to call from the view.<br> Hope this helps you.</p> <p><strong>Update:</strong> </p> <pre><code>foreach( $data as $key =&gt; $each ) { $data[$key]['intTaskID'] = $each['intTaskID']; $data[$key]['team_id'] = $this-&gt;get_user_team_task_query( $each['intTaskID'] ); foreach($data[$key]['team_id'] as $key =&gt; $each) { $data[$key]['team_name'] = $this-&gt;get_team_name( $each['intTeamID'] ); #fetching of the teamname and saving in the array $user_name = $this-&gt;get_fn_ln_from_userid( $each['intUserID'] ); #you are returning tbl_person.txtFirstname, tbl_person.txtLastname from get_fn_ln_from_userid() with -&gt;result()? $data[$key]['first_name'] = $user_name-&gt;txtFirstname; #changes here $data[$key]['last_name'] = $user_name-&gt;txtLastname; #changes here } } </code></pre> <p>Always remember what you are returning from your functions and change your code as expected results you will be getting. Try to debug your code in the loop for the returned values and change your code accordingly. For example : </p> <pre><code>foreach( $data as $key =&gt; $each ) { $data[$key]['intTaskID'] = $each['intTaskID']; $data[$key]['team_id'] = $this-&gt;get_user_team_task_query( $each['intTaskID'] ); foreach($data[$key]['team_id'] as $key =&gt; $each) { echo "&lt;pre&gt;";print_r( $each );die; #will print the $each $data[$key]['team_name'] = $this-&gt;get_team_name( $each['intTeamID'] ); #fetching of the teamname and saving in the array $user_name = $this-&gt;get_fn_ln_from_userid( $each['intUserID'] ); #you are returning tbl_person.txtFirstname, tbl_person.txtLastname from get_fn_ln_from_userid() with -&gt;result()? echo "&lt;pre&gt;";print_r( $user_name );die; #will print the returned results from the get_fn_ln_from_userid() $data[$key]['first_name'] = $user_name-&gt;txtFirstname; #changes here $data[$key]['last_name'] = $user_name-&gt;txtLastname; #changes here } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload