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 trialJohn Norris
21,145 PointsThe first list item falls to the bottom.
When I preview todo.php in the browser... The first item drop to the bottom of the page wrapped in a <pre></pre> tag. Why does this happen?
// My Code
<?php
include 'list.php';
foreach ($list as $key => $item) {
echo $key . ' = ' . $item['title'] . "<br>\n";
}
echo "<table>";
echo "<tr>";
echo "<th>Title</th>";
echo "<th>Priority</th>";
echo "<th>Due Date</th>";
echo "<th>Complete</th>";
echo "</tr>";
foreach ($list as $item) {
echo "<tr>";
echo "<td>" . $item['title'] . "</td>\n";
echo "<td>" . $item['priority'] . "</td>\n";
echo "<td>" . $item['due'] . "</td>\n";
echo "<td>";
if ($item['complete']) {
echo "Job's done!";
} else {
echo "More work?!";
}
echo "</td>\n";
echo "</tr>";
}
echo '</table>';
Is that just Chrome being silly? It looks fine in page source, but I see it's been wrapped (like so <pre>0 = Laundry</pre>) in Chrome DevTools Elements tab. So 0 = Laundry is at the bottom of the page. How do I prevent this from happening?
1 Answer
Daniel Baker
15,369 PointsThere is some explanation here. Looks like it is chrome. StackOverflow
I just wrapped the loop in a div to fix it.
echo '<div>';
foreach ($list as $key => $item) {
echo $key . '=' . $item['title'] . "<br />\n";
}
echo '</div>';
Daniel Baker
15,369 PointsDaniel Baker
15,369 PointsWhich track are you in, give me a URL?