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 trialDavid Reid
19,691 PointsNeed 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 :)
<?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
34,055 PointsYou'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
}
Benjamin Larson
34,055 PointsYou'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.
David Reid
19,691 Pointsforeach ($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
David Reid
19,691 PointsDavid Reid
19,691 PointsThanks Benjamin!1 Made it harder in my head than it actually is :)