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

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.

index.php
<?php
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.:
$result['member_id']

not

$result($member_id)

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

e.g.:

foreach ($results as $result) {
....
}