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 trialDanielle Evans
2,282 PointsNot Getting the Same Result
So at 3:53 of the Todo App video Alena gets a result of all "No"s. I get a result of all "Yes"s. And it's weird because only ONE item in the list of arrays in the list.php file is "Yes," meaning it's Complete. What did I do wrong?
Plus the Due Dates are different from the video but I think the list.php file she's using is different from the one we currently download from the teacher's notes.
There's 2 files being worked with in this example, here's both:
The todo.php:
<?php
include 'list.php';
$status = false;
$order = array();
foreach ($list as $key => $item) {
if ($item['complete'] == $status) {
$order[] = $key;
}
}
//var_dump($order);
//var_dump($list);
echo '<table>';
echo '<tr>';
echo '<th>Title</th>';
echo '<th>Priority</th>';
echo '<th>Due Date</th>';
echo '<th>Complete</th>';
echo '</tr>';
foreach ($order as $id) {
echo '<tr>';
echo '<td>' . $list[$id]['title'] . "</td>\n";
echo '<td>' . $list[$id]['priority'] . "</td>\n";
echo '<td>' . $list[$id]['due'] . "</td>\n";
echo '<td>';
if ($item['complete']) {
echo 'Yes';
} else {
echo 'No';
}
echo "</td>\n";
echo '</tr>';
}
echo '</table>';
//var_dump($list);
//echo $list[0]['title'];
?>
And the list.php:
<?php
$list = array();
$list[] = array(
'title' => 'Laundry',
'priority' => 2,
'due' => '06/09/2016',
'day' => 0,
'repeat' => true,
'complete' => false,
);
$list[] = array(
'title' => 'Dishes',
'priority' => 2,
'due' => null,
'day' => 0,
'repeat' => true,
'complete' => false,
);
$list[] = array(
'title' => 'Dust',
'priority' => 3,
'due' => null,
'day' => 5,
'repeat' => true,
'complete' => false,
);
$list[] = array(
'title' => 'Vacuum',
'priority' => 1,
'due' => '06/09/2016',
'day' => 1,
'repeat' => true,
'complete' => false,
);
$list[] = array(
'title' => 'Make Dinner',
'priority' => 1,
'due' => null,
'day' => 0,
'repeat' => true,
'complete' => false,
);
$list[] = array(
'title' => 'Clean Out Fridge',
'priority' => 2,
'due' => '07/30/2016',
'day' => 0,
'repeat' => true,
'complete' => true,
);
?>
2 Answers
Claudio Medina
Full Stack JavaScript Techdegree Student 4,751 PointsYou forgot to change one variable inside the second foreach loop
from:
if ($item['complete']) {
echo 'Yes';
} else {
echo 'No';
}
to
if ($list[$id]['complete']) {
echo 'Yes';
} else {
echo 'No';
}
Caleb Kleveter
Treehouse Moderator 37,862 PointsChange your loop:
foreach ($list as $key => $item) {
if ($item['complete'] == $status) { // This line here
$order[] = $key;
}
}
To this:
foreach ($list as $key => $item) {
if ($item['complete']) { // Should look like this
$order[] = $key;
}
}