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

Robert Valencia
PLUS
Robert Valencia
Courses Plus Student 3,735 Points

Not sure what I’m doing, I’m finding this quiz very unrelated to the previous video, I’m missing something very basic.

//the code from the last video is as follows: $results = $db->query("SELECT title, category FROM Media"); var_dump( $results->fetchAll(PDO::FETCH_ASSOC) );

//however, as I understand the instructions, they mention that this has already been declared.

//thus, I am unclear as to how to write what is next. an example would be appreciated.

index.php
<?php
include "helper.php";


foreach($results as $level)
  $email->send_offer($fullname,$email,$member_id);

/* 
 * helper.php contains
 * $results->query("SELECT member_id, email, fullname, level FROM members");
 */

1 Answer

Chris Shaw
Chris Shaw
26,676 Points

Hi Robert Valencia,

It may seem unrelated, but the quiz is directly focused on the use of the PDO fetchAll method which was explained and then we were shown how to dump the results of to see them visually. Now, instead of that, the quiz wants us to iterate through the results like we would if we had a static associative array which has been covered in the below two courses.

In the case of this challenge, we need to take those learnings and iterate through the results returned and pass the data for each member to the send_offer function by selecting the key/value pairs using the key names described by the task.

foreach ($results->fetchAll(PDO::FETCH_ASSOC) as $result) {
  send_offer($result['member_id'], $result['email'], $result['fullname'], $result['level']);
}

Happy coding!

Robert Valencia
Robert Valencia
Courses Plus Student 3,735 Points

Thank you SO MUCH Chris! This is extremely helpful! I really appreciate it!