Welcome Guest, Not a member yet? Register   Sign In
Running a Query with in a foreach loop
#1

[eluser]jshultz[/eluser]
I feel like I'm on the right track with this but I'm missing something.

I have a query that runs through a list of projects by the user id:

Code:
function getByUserId() {
    $user_id = $this->tank_auth->get_user_id();
    return $this->db->get_where('projects', array('user_id'=>$user_id));
}

On the view page I have a foreach loop that cycles through the code:

Code:
<table>
        <tr><th>Project</th><th>Due Date</th></tr>
    &lt;?php foreach($projects->result() as $row): ?&gt;
    
        <tr>
            <td><p>&lt;?=$row->project_name?&gt;</p></td>
            <td><p>&lt;?=$row->due_date?&gt;</p></td>
            <td></td>
        </tr>
    
    &lt;?php endforeach; ?&gt;
    </table>

Now, I'm wanting to insert before the end the following code:

Code:
&lt;?php foreach($tasks->result() as $row): ?&gt;
        <tr>
            <td><p>&lt;?=$row->tasks?&gt;</p></td>
            <td><p>&lt;?=$row->due_date?&gt;</p></td>
            <td></td>
        </tr>
    &lt;?php endforeach; ?&gt;

As you might imagine, it's going to get a list of tasks associated with the project that it just cycled through. I'm sure it's simple, I just want to pass a variable to this function:

Code:
function getTasksByProjectId($ID) {
    return $this->db->get_where('tasks', array('projectid'=>$projectID));
}

My idea is that when it goes through the loop it has the ID of the project in the array and somehow magical elves will get that id to the function and tell it what tasks it should be spitting out. Unfortunately for me, I haven't found the elves that are going to be relaying that information.

Any suggestions?


Messages In This Thread
Running a Query with in a foreach loop - by El Forum - 08-09-2009, 10:56 PM
Running a Query with in a foreach loop - by El Forum - 08-10-2009, 12:04 AM
Running a Query with in a foreach loop - by El Forum - 08-10-2009, 02:07 AM
Running a Query with in a foreach loop - by El Forum - 08-10-2009, 07:52 AM
Running a Query with in a foreach loop - by El Forum - 08-10-2009, 08:34 AM
Running a Query with in a foreach loop - by El Forum - 08-10-2009, 08:56 AM
Running a Query with in a foreach loop - by El Forum - 08-10-2009, 09:41 AM
Running a Query with in a foreach loop - by El Forum - 08-10-2009, 10:27 AM
Running a Query with in a foreach loop - by El Forum - 08-10-2009, 11:12 AM
Running a Query with in a foreach loop - by El Forum - 08-10-2009, 11:39 AM
Running a Query with in a foreach loop - by El Forum - 08-10-2009, 04:13 PM
Running a Query with in a foreach loop - by El Forum - 08-10-2009, 05:20 PM
Running a Query with in a foreach loop - by El Forum - 08-10-2009, 08:22 PM
Running a Query with in a foreach loop - by El Forum - 08-11-2009, 04:15 PM
Running a Query with in a foreach loop - by El Forum - 08-12-2009, 02:38 AM
Running a Query with in a foreach loop - by El Forum - 08-12-2009, 03:40 AM
Running a Query with in a foreach loop - by El Forum - 08-12-2009, 08:38 AM
Running a Query with in a foreach loop - by El Forum - 08-13-2009, 09:05 AM
Running a Query with in a foreach loop - by El Forum - 08-13-2009, 09:18 AM
Running a Query with in a foreach loop - by El Forum - 08-13-2009, 09:33 AM
Running a Query with in a foreach loop - by El Forum - 08-15-2009, 10:34 PM



Theme © iAndrew 2016 - Forum software by © MyBB