Interacting with Databases code example
s3b4stian opened this issue · comments
Sebastian Rapetti commented
Hello!
This code example in http://www.phptherightway.com/#databases_interacting could be changed, for performance reasons, from this:
function getAllFoos($db) {
return $db->query('SELECT * FROM table');
}
foreach (getAllFoos($db) as $row) {
echo "<li>".$row['field1']." - ".$row['field1']."</li>"; // BAD!!
}
to this:
function getAllFoos($db) {
return $db->query('SELECT * FROM table');
}
$result = getAllFoos($db);
foreach ($result as $row) {
echo "<li>".$row['field1']." - ".$row['field1']."</li>"; // BAD!!
}
Josh Lockhart commented
Done. Thanks.
Sebastian Rapetti commented
Hi check the snippet on the web page, there is an extra s
$results = getAllFoos($db);
foreach ($resultss as $row) {
echo "<li>".$row['field1']." - ".$row['field1']."</li>"; // BAD!!
}
Josh Lockhart commented
ha I must have fat-fingered that one. Just pushed a fix.