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 trialmohamad hossein Damad
4,430 Pointsis the PDOStatement Object loopable?? or u should fetch it first?
https://teamtreehouse.com/library/crud-operations-with-php/creating-records/reading-data
i cant underestand the question just help me underestand the question plz
<?php
function get_podcasts() {
include 'connection.php';
//add code here
return $db->query("select * from podcasts");
}
var_dump();
2 Answers
mohamad hossein Damad
4,430 Pointsi gave u the link. im not sure u got the question i have the problem in. its the next question im not feeling well with!!
Marc Busby
35,550 PointsYea I had to complete the first part to see the second part. Sorry I understand now.
So basically you have the function working. So now you need to echo out the podcast['title'] and podcast['website']. So below the function create a foreach loop using the function and output the titles and website.
<?php
echo '<ul>';
foreach (get_podcasts() as $podcast) {
echo "<li>" . $podcast['title'] . " " . $podcast['website'] . "</li>";
}
echo '</ul>';
You should also put you're pdo call in a try catch block.