Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP Integrating PHP with Databases Querying the Database with PHP Working with Results

In the PHP section "integrating PHP with DataBases, in the challenge "Working with Results", Im not sure how to do this.

The TIP is... we used this method in the previous video. I went back through the past 2 videos several times and cannot figure out how to extract the data from $results in order to pass them through the function.

include "helper.php";

try {
    $results = $db->query(
        "SELECT member_id, email, fullname, level FROM members"
} catch (Exception $e) {
    echo $e->getMessage();
//add code below this line
$x = send_offer($results($member_id), $results($email), $results($fullname), $results($level));

2 Answers

Thank you for your help.
Instead of tossing me a fish, you taught me how to fish, even though I was about to sell the boat...lol

  1. You have to loop through the results.
  2. You have to use square brackets, not parentheses. Also, you have to use the column names instead of variables. E.g.:



Square brackets make sense, but I guess I don't understand the 'loop through the results' part.


foreach ($results as $result) {