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 trialPatrik Horváth
11,110 Pointsi m lost in her video she never show anything about send_offer() -_-
check this chalange and watch this video it looks like she SKIPS a lot of think because
you cant SHOW content on website by just calling Fatch ASSOC and she never described method send_offer
so idk parameters for this method =\
<?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
while ($row = $results->fetchAll(PDO::FETCH_ASSOC)) {
}
3 Answers
Matthias Margot
7,236 PointsIn the challenge description it says this: "This helper file also contains a function to send_offer. The send_offer function accepts the following arguments: $member_id, $email, $fullname, $level." So you have this function :
<?php
function send_offer($member_id, $email, $fullname, $level) {
//sends email to member using given parameters given
}
?>
Also check out the difference between these two. You're using the wrong one if you wanna call the fetch method in the conditional of a while statement.
Try again with this information and if you still can't do it let me know I'll help you out.
Patrik Horváth
11,110 Pointsyea here is Final Loop :)
foreach($results as $row) {
send_offer($row['$member_id'], $row['$email'], $row['$fullname'], $row['$level']);
}
Gary Logue
13,831 Points<?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
$result = $db->fetchAll();
foreach($result as $row) {
send_offer($row['$member_id'], $row['$email'], $row['$fullname'], $row['$level']);
}
?>
Think I am going to have to go back a good few videos, I am lost, here is my code. What am I missing?
Gary Logue
13,831 PointsI have just seen my issue. Thanks so much guys "results" not "result".
You guys have saved my from pulling the remainder of my hair out. Cheers folks lol
Patrik Horváth
11,110 PointsPatrik Horváth
11,110 Pointsthenks i watch all videos doing all whot is here but doesnt saw this method :)
yup fatchAll is for MySQLi WHILE loop or PDO Foreach :)
Gary Logue
13,831 PointsGary Logue
13,831 PointsHi Matthias
I am still stuck on this challenge could you please shed some more light on it?
I have used the code you put above but still no joy. Thanks in advance