Maybe my problem is something about the scopes of methods and vars but I do not get it and can somebody suggest me how to do it the right way?
I have this in my included file User_query.php:
$stmt = $db->prepare("SELECT * FROM users WHERE user_id=:user_id");
$stmt->bindValue(':user_id', $user_id, PDO::PARAM_INT);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
I have this in my index.php file:
include APP_PATH . 'User_query.php'; /* I have just an query here */
Pages::buildPage();
My class method:
class Pages {
public function buildPage() {
include APP_PATH . 'Headers.php'; /* I try to print $row['something'] in-here */
include APP_PATH . 'Contents.php'; /* I think this will not work either... */
include APP_PATH . 'Footers.php'; /* ... and I will get undefined indexes */
print $row['something'] /* Even this do not work, no difference I think than the above */
}
}
And when I try to print something from the database query in my header files using print $row['something'] I have "Notice: Undefined variable: row" error. I am confused. (I did it this way to learn the classes and methods)
there is no any array or variable named as $row['something']
That is the reason for giving error..