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 trialjaneporter
Courses Plus Student 23,471 Pointsloop through??? How when i'm not shown an example???
How am I supposed to 'loop through' the database when I don't know how to?
<?php
include "helper.php";
/*
* helper.php contains
* $results->query("SELECT member_id, email, fullname, level FROM members");
*/
2 Answers
Simon Coates
28,694 Pointsthe following code works:
<?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'] );
}
The basic idea is that they've already run the query, so you can just continue from that point. If you compare it against the database pattern, you should be able to see how it relates to prior examples. (a lot of people struggle with this question)
janeporter
Courses Plus Student 23,471 Pointsthank you. i knew both pieces were necesary, just didn't know how to put them together.