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

Siraj Khan
Siraj Khan
3,451 Points

I do not know know how to Loop through the results and pass them to the send_offer function. Please help

I do not know know how to Loop through the results and pass them to the send_offer function. Can anyone please help me understand and solve this.!?

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

1 Answer

Tim Stride
Tim Stride
13,457 Points

Iā€™m not 100% sure this is right, but this is how I would start looping through the results and turning them into the variables that the send_offer function uses. (Adding the code below to that provided)

while($row = $results->fetch(PDO::FETCH_ASSOC)) {
          $member_id = $row['member_id'];
$email = $row['email'];
$fullname = $row['fullname'];
$level = $row['level'];

send_offer($member_id, $email, $fullname, $level);

      }