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 trialcleancoder
8,307 PointsQuerying the Database with PHP
I am struggling with this particular assignment. I am not sure how to structure this code to do what the assignment is asking.
Rant: Some of these challenges really feel unfair. I feel I'm being asked to produce things I don't fully understand yet. I've only seen it demonstrated once! How do they expect me to suddenly be able to apply and work with it when I'm not even sure what the heck I just saw? Maybe this course should come AFTER the PHP objects course so I have a better understanding of how these things work. End of rant.
<?php
include "helper.php";
/*
* helper.php contains
* $results->query("SELECT member_id, email, fullname, level FROM members");
*/
$send_offer = $results->query("SELECT member_id, email, fullname, level FROM members");
Simon Coates
28,694 PointsThe query method has already run. The task is to loop over the results, and for each pass some values to a method called send_offer. a lot of people trip over this challenge.
cleancoder
8,307 PointsThank you both for your tips and helpful advice. It worked and I am now back on track!
Enjoy your holiday weekends!
Back to coding... Shanen
2 Answers
Simon Coates
28,694 PointsThere are a couple different possible variations, but the following seems to be accepted:
<?php
include "helper.php";
/*
* helper.php contains
* $results->query("SELECT member_id, email, fullname, level FROM members");
*/
$rows = $results->fetchall();
foreach($rows as $row){
send_offer($row['member_id'], $row['email'], $row['fullname'], $row['level'] );
}
cleancoder
8,307 PointsThank you very much, Simon! I appreciate the time you took to provide this. I'm gonna try this and I'm hoping it'll get me through the challenge (after I eat my ice cream).
cleancoder
8,307 PointsThanks, Walter! I appreciate the advice. You're absolutely correct. I did do that this time, as that has actually helped me in the past, but I just don't get this right now - and I'm kinda steamed over it. I'm going to take a break, eat some ice cream, watch a Top Chef rerun and come back fresh-faced. I just can't handle this right now.
Walter Allen
iOS Development with Swift Techdegree Student 16,023 PointsWalter Allen
iOS Development with Swift Techdegree Student 16,023 PointsHey, Shanen. I had seen your question when I was surfing on my phone a little while ago, but couldn't answer because I didn't feel like typing on my phone keyboard... Now, back on my laptop, I see that someone else has already provided you with the answer, but I did want to see if I could help out with your rant. :)
I totally understand that some of this can be frustrating and confusing. I found that the best way to find an answer if I didn't feel quite ready was to go back and rewatch the video, making sure that I'm following along and really dissecting what they are doing in it and actually writing the code as I watch. That helps me at least. I'm sure we all learn differently, but that's my advice.
Sometimes, just like re-reading something multiple times in a textbook, it might help to re-watch the video multiple times and go back through their example code multiple times as well.
That said, I wish you all the luck as you continue you learning journey. Let me know if you need any help. I'll be glad to help out if I'm near the keyboard. :)