Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJim Morrison
13,394 PointsCRUD Operations with PHP (Duplicated total rows)
In the Reading and Writing Reports section, I have found that the 'Project total' row is being duplicated or projects with more than 1 task.
I downloaded the project files from the teachers notes and the issue is happening with that code too.
Heres a screen shot of the issue: http://postimg.org/image/zfxmaim8x/
Here is my code:
<?php
$total = $project_id = $project_total = 0;
$tasks = get_task_list($filter);
foreach ($tasks as $item) {
if ($project_id != $item['project_id']) {
$project_id = $item['project_id'];
echo "<thead>\n";
echo "<tr>\n";
echo "<th>" . $item['project'] . "</th>\n";
echo "<th>Date</th>\n";
echo "<th>Time</th>\n";
echo "</tr>\n";
echo "</thead>\n";
}
$project_total += $item['time'];
$total += $item['time'];
echo "<tr>\n";
echo "<td>". $item['title'] . "</td>\n";
echo "<td>". $item['date'] . "</td>\n";
echo "<td>". $item['time'] . "</td>\n";
echo "</tr>\n";
if (next($tasks)['project_id'] != $item['project_id']) {
echo "<tr>\n";
echo "<th class='project-total-label' colspan='2'>Project Total</th>\n";
echo "<th class='project-total-number'>$project_total</th>\n";
echo "</tr>\n";
$project_total = 0;
}
}
?>
Any help is greatly appreciated! Thanks