Próbuje się zmagać z OOP i stanąłem przed taki problemem z paginatorem. Gdy robię to strukturalnie wszystko działa. Chciałbym teraz przerzucić kod do metody w klasie na zewnątrz i odczytać ją w pliku finalnym. Ostatecznie dostaję komunikaty:
Notice: Undefined variable: articles in C:\xampp\htdocs\nauka\ooplogin\list.php on line 59
Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\nauka\ooplogin\list.php on line 59
Notice: Undefined variable: pages in C:\xampp\htdocs\nauka\ooplogin\list.php on line 71
oraz zero wyników. Co zrobiłem źle?
list.php:
<?php require_once "functions.php"; $user = new LoginRegistration(); if(!$user->getSession()) { } ?> <div class="content"> <p class="userlist"> All user from list </p> <table class ="tbl_one"> <tr> <th>Serial</th> <th>Name</th> </tr> <?php $user->getList(); foreach($articles as $article): ?> <tr> <?php endforeach; ?> </tr> </table> <div class="paginator"> <?php for($x = 1; $x <= $pages; $x++): ?> <?php endfor; ?> </div> </div>
funkcja z functions.php:
public function getList() { $start = ($page > 1) ? ($page * 3) - 3 : 0; $articles = $pdo->prepare("SELECT SQL_CALC_FOUND_ROWS id, username FROM users LIMIT {$start}, 3"); $articles->execute(); $articles = $articles->fetchAll(PDO::FETCH_ASSOC); $total = $pdo->query("SELECT FOUND_ROWS() as total")->fetch()['total']; }