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

Need PHP help

Hi! I can't seem to understand what to do in this instance. The tip says to use the same method as the video before but I don't understand. I am trying to pass the $results array as the parameter for the send_offer func.

appreciate any help in letting me know what I am doing wrong. thanks :)

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

$results = $results->fetchAll();
send_offer();

2 Answers

Benjamin Larson
Benjamin Larson
34,055 Points

You'll just need one foreach loop for this. The form of foreach ($inner_arr as $key => $value) is only needed when you need the element's key returned, but in this case we are designating the keys inside the send_offer() function.

<?php
foreach ($results as $member) {  // $member could be named anything
  send_offer($member['member_id']); // you'll need to add the other arguments
}

Thanks Benjamin!1 Made it harder in my head than it actually is :)

Benjamin Larson
Benjamin Larson
34,055 Points

You'll also need to add a foreach() loop to go through each of the members from the $results and then call the send_offer() function from within that loop while passing the member details as arguments.

If you need more hints let me know, but give it a try.

foreach ($results as $inner_arr) {

  foreach ($inner_arr as $key => $value) {

    send_offer(



              );

  }
} 

I've got this far but I can't quite get how to send the args in. Gives me errors