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

Querying 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.

index.php
<?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");
Walter Allen
seal-mask
.a{fill-rule:evenodd;}techdegree
Walter Allen
iOS Development with Swift Techdegree Student 16,023 Points

Hey, 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. :)

Simon Coates
Simon Coates
28,694 Points

The 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.

Thank 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
Simon Coates
28,694 Points

There 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'] );
}

Thank 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).

Thanks, 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.