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 trialGabor Sornyei
Courses Plus Student 4,118 PointsLooks like challenge 1 not valid anymore
No idea what it means, I just can't figure out what they mean by displaying the data. Echoing it to the console, or to a webpage? In a single line or in two separate lines? Should I use an html tag? If yes which one? So I'm lost. Any help appreciated.
<?php
function get_podcasts() {
include 'connection.php';
//add code here
return $db->query('SELECT * FROM podcasts');
}
echo "<ul>";
foreach(get_podcasts() as $item) {
echo "<li>" . $item['title'] . " " . $item['website'] . "</li>"
}
echo "</ul>";
2 Answers
andrewgabriel
18,106 PointsHi Gabor, Let me break things down for you and hopefully that should make it a bit better. So I see initially youβve declared a function called get_podcasts which queries EVERYTHING from the podcasts table.
Below that you initiate a foreach loop which will call the get_podcasts function and assign every value it gets from the query and store it in a variable called item.
Since you have wrote your query to SELECT * (aka EVERYTHING) you echo out ONLY the title and website data that you get from the get_podcasts function.
Lastly, all of that is wrapped around an unordered list and displayed in a list item inside that unordered list so that it shows as bullet points to the user on the front-end.
Another you could have displayed these results would be by SELECT title, website FROM podcasts instead of SELECT * and then extracting specific parameters but thatβs just only a minor difference. The instructor might have done this so that they could use other parameters without having to write a query for every single item they want to extract.
I certainly hope this have made things seem a little more clear but feel free to ask any other questions. Integrating SQL with PHP can be a little confusing at first but within no time things will start clicking and you will master it! Keep up the good work :)
Gabor Sornyei
Courses Plus Student 4,118 PointsThank you Andrew, but I don't think that querying all of the fields is a problem if you want to use only a subset of those. But I tried to resubmit the solution above and now it was accepted :) Maybe a moderator was checking on the algorithm of the challenge and did something to it. Thank you again!