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 Integrating PHP with Databases Querying the Database with PHP Working with Results

Integrating PHP with Database - Coding Challenge - Task 1 - Send Offer to Members Challenge

Hi ! Can someone explain to me how am I supposed to solve this challenge, particularly how am i supposed to loop through the $results object and send its results to the send_offer() method

include "helper.php";

 * helper.php contains
 * $results->query("SELECT member_id, email, fullname, level FROM members");

2 Answers

The helper.php contains the $results PDOStatment object built from the query, so essentially all you have to do is build some sort of loop (easy choice would be a foreach probably) and pass that $results object in as the iterable. It would probably look something like

foreach ($results as $row) {}

Then inside your loop block, you'll separate out the values and use them as arguments when calling the send_offer() method. To access the individual values (which are named in the commented query within the Challenge), you would just call them by name like this:


So, to build your send_offer() call, you'd just pass in the required $row["named_value"]s as arguments within the call, and you'd have it finished off. I'm gonna drop this link to some solid and relatively easy to understand information on PDOs and how to work with them. It's a decent read and worth tossing a bookmark on to reference later down the line.

Thank you soooo much, great explanation :D

Glad to help :)