If you do a foreach and you have something like: foreach($variable1 as $variable2) then isn’t variable2 being defined in the argument?
I have the following handler
[php]<?php
include_once ‘db_connect.inc.php’;
try {
$result = $pdo->query(‘SELECT id, name from author’);
}
catch (PDOException $e) {
$error = ‘Error fetching authors from database’;
include ‘error,html.php’;
exit();
}
foreach ($results as $row) {
$authors[] = array(‘id’ => $row[‘id’], ‘name’ => $row[‘name’]);
}
include ‘authors.html.php’;
?>[/php]
and then the page that should display the content
[php]<?php include_once $_SERVER[‘DOCUMENT_ROOT’] .
‘Netbeans/PHP Power/includes/helpers.inc.php’; ?>
Manage Authors
-
<?php foreach ($authors as $author): ?>
-
<?php htmlout($author['name']); ?>
<?php endforeach; ?>
On the page that should display the content I get the following error:
Notice: Undefined variable: authors in C:\wamp\www\Netbeans\PHP Power\admin\authors\authors.html.php on line 13 (which is the file above on line 13)
I would like to understand this so any help would really be appreciated.