大家好,我正在使用 codeigniter 构建项目管理系统。
我的模型中有一个函数来显示一个项目以及与之关联的任务。$projectId = 1 仅用于测试目的。
function getAllProjects($projectId = 1)
{
$this->db->select('*');
$this->db->from('projects');
$this->db->where('projects.projectId', $projectId);
$this->db->join('projectTasks', 'projects.projectId = projectTasks.projectId');
$this->db->join('tasks', 'projectTasks.taskId = tasks.taskId');
$projects = $this->db->get();
return $projects;
}
然后在我看来我让它显示结果
<?php if($projects->num_rows() > 0): ?>
<table width="100%">
<?php foreach($projects->result() as $p): ?>
<tr>
<td><?php echo $p->projectId; ?></td>
<td><?php echo $p->projectName; ?></td>
<?php foreach($projects->result() as $g): ?>
<td><?php echo $g->taskName; ?></td>
<td><?php echo $g->taskHours; ?></td>
<td><?php echo $g->taskCost; ?></td>
<?php endforeach; ?>
</td>
</tr>
<?php endforeach; ?>
</table>
<?php else: ?>
<p>No projects at this time.</p>
<?php endif; ?>
哪个返回这个
ID - Project Name - Task Name - Task Hours - Task Cost (**to show you what field is what**)
1 The Range 702 Contact Form 10 100 Custom Logo Desgin 10 100 Custom Login From 5 75
1 The Range 702 Contact Form 10 100 Custom Logo Desgin 10 100 Custom Login From 5 75
1 The Range 702 Contact Form 10 100 Custom Logo Desgin 10 100 Custom Login From 5 75
有人可以告诉我如何制作它,因此它只显示一次项目信息,然后显示与项目关联的每个任务。现在,对于与项目关联的每个任务,它都会再次列出项目和所有任务。
表
-----------------------
| projects |
-----------------------
| projectId | (Primary)
| projectName |
| projectHours |
| projectDeadline |
| projectStartDate |
| projectTasks |
| projectUsers |
| projectNotes |
| |
-----------------------
-----------------------
| projectTasks |
-----------------------
| projectTasksId | (Primary)
| projectId | (FK project->projectId)
| taskId | (FK tasks->taskId)
| |
-----------------------
--------------------
| tasks |
--------------------
| taskId | (Primary)
| taskName |
| taskHours |
| taskCost |
| |
--------------------