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 trialRonaldo Fialho
5,105 PointsSummarizing Project Time!
Notice: Undefined index: project in /home/treehouse/workspace/reports.php on line 44
the code seems to be correct... function get_task_list($filter = null) { include 'connection.php';
$sql = 'SELECT tasks.*, projects.title AS Project FROM tasks
'
. 'JOIN projects
ON tasks.project_id = projects.project_id';
$orderBy = ' ORDER BY date
DESC';
if($filter) {
$orderBy = " ORDER BY projects.title ASC, date DESC";
}
try{ $results = $db->prepare($sql . $orderBy); $results->execute(); } catch(Exception $e) { echo "Error!: " . $e->getMessage() . "<br>"; return array(); } return $results->fetchAll(PDO::FETCH_ASSOC); } //THIS IS THE FUNCTION. ITS EXACTLY THE SAME AS THE TUTORIAL // AND BELOW THE FOLLOWING CODE <?php $total = $project_id = 0; foreach(get_task_list($filter) 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>";
}
$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";
}
?>
ANY HELP IS TOO MUCH APPRECIATE IT!!
1 Answer
Simon Coates
28,694 PointsI think you're using an incorrect index to access the arrary. Eg.
<?php
$array = array(
"foo" => "bar",
);
echo $array['notexistentkey'];
produces
<b>Notice</b>: Undefined index: notexistentkey in <b>[...][...]</b> on line <b>7
Maybe use a var_dump to see that the value you're using matches your expectation. It may be something trivial like a case mismatch.
Ronaldo Fialho
5,105 PointsThanks so much for your help and time Simon. I was following the video exactly the same that Alena was doing. the problem was on 'project' it was supposed to be capital P. I used the var_dump as you suggested it could see that. thx once again!!
Simon Coates
28,694 PointsSimon Coates
28,694 Pointsto format code correctly (treehouse uses something called 'markdown'), use three backticks (on the key with the tilde) before and after the code. As the code doesn't show line numbers, maybe include a comment on the line where the problem occurs (eg //line 44)