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 trialsuyash patankar
2,310 PointsWhat is wrong? I am getting error 'you have not output first course'
Please let me know what is wrong in it, I have written code as per video.
<?php
/*
{
"name": "Username",
"profile_name": "profile_username",
"profile_url": "http://myapi.net/profile_username"
"courses": [
{ "name": "WordPress Plugin Development" },
{ "name": "WordPress Theme Development" },
{ "name": "Introduction to PHP" }
]
}
*/
?>
<ul>
<?php for( $i = 0; $i < count($my_plugin_profile->courses); $i++ ): ?>
<? echo $my_plugin_profile->{'courses'}[$i]->{'name'}; ?>
<?php endfor; ?>
</ul>
1 Answer
Greg Kaleka
39,021 PointsHi Suyash,
There are two problems with your answer. One of them is a PHP problem, the other is an HTML problem.
- You need to open your php block with
<?php
, not just<?
- You're just spitting out the names one after the other. You need to wrap each course name in
<li></li>
tags
<?php
/*
{
"name": "Username",
"profile_name": "profile_username",
"profile_url": "http://myapi.net/profile_username"
"courses": [
{ "name": "WordPress Plugin Development" },
{ "name": "WordPress Theme Development" },
{ "name": "Introduction to PHP" }
]
}
*/
?>
<ul>
<?php for( $i = 0; $i < count($my_plugin_profile->courses); $i++ ): ?>
<li>
<?php echo $my_plugin_profile->{'courses'}[$i]->{'name'}; ?>
</li>
<?php endfor; ?>
</ul>
suyash patankar
2,310 PointsThank you very much Greg
velochicdunord
4,816 Pointsvelochicdunord
4,816 PointsFWIW, I'm having trouble with the same exercise.