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

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