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 trial

PHP PHP Arrays and Control Structures PHP Loops Foreach Loops

Piyush Patel
Piyush Patel
17,253 Points

Why does my workspace never show me the desired result?

I'm trying to work on the workspace with PHP but it never displays as it displays in the videos.

when I echo, it displays tags, rather than it's visual representation.

For example, if I write:

echo '<td>' . $item . '</td>';

It displays

<td>Item</td>

but not the new cell with "Item" in it.

Why is it so?

Jay Padzensky
Jay Padzensky
4,731 Points

Hi Piyush,

If you're able to post your Workspace code here with Markdown formatting, it may be easier for individuals to review your code and offer some thoughts. The "Markdown Cheatsheet" is available when editing your original post to help you include the necessary characters to format the code.

4 Answers

I think you didn't notice that she's not showing the result from the Workspace shes showing it on the browser. You will need to press the Preview Workspace to preview it on the browser.

It wasn't working for me either. The list was being echoed after the table and no formatting was occurring. So what I did was break the php into separate blocks, inserted the foreach function block exactly where I want it into the table.

<?php
include 'list.php';
?>
<html>
    <table>
        <tr>
            <th>Title</th>
            <th>Priority</th>
            <th>Due Date</th>
            <th>Complete</th>
        </tr>
        <?php 
            foreach ($list as $item ){
                echo '<tr>';
                echo '<td>'.$item['title']."</td>";
                echo '<td>'.$item['priority']."</td>";
                echo '<td>'.$item['due']."</td>";
                echo '<td>';
                if ($item['complete']){
                    echo "Yes";
                } else {
                    echo "No";
                }
                echo '</td>';
                echo '</tr>';
            }    
        ?>
    </table>
</html>
Piyush Patel
Piyush Patel
17,253 Points

I copied the finished code from Downloads and still that one also displays incorrectly. It is not my code problem and when I write the same code in XAMPP, it displays correctly.

Piyush Patel
Piyush Patel
17,253 Points

I believe either my Workspace is outdated or probably something else! Thanks for the advice though!