Hey folks,
so I added a rating system to my php generated table and decided to build upon the rating system structure to make the table sortable and paginated.
The sortable part worked easily but I am stuck with the pagination part.
This is the part of the function which deals with pagination and all of that gets posted on index.php
if(!isset( $_GET['p']) ){$_GET['p'] =0;}
$per_page= 5;
$sqlzine= "SELECT * FROM `banner_clicks` WHERE `active` = 1" ;
$page= mysql_num_rows ( $this->objDb->query($sqlzine));
$pages= ceil($page / $per_page);
$sql = "SELECT * FROM `banner_clicks` WHERE `active` = 1 ORDER BY ".$order_var." LIMIT ".$_GET['p'].",". $per_page or die ('sql2 not working');
$statement = $this->objDb->query($sql);
return $statement->fetchAll(PDO::FETCH_ASSOC);
}
On the index.php file I use a for loop right after a foreach loop, displaying the database entries, to display the numbers at the bottom of the table.
for ( $i=0; $i<$pages; $i++){
echo ($i == $_GET['p'] / $per_page) ? '<strong> <a href="index.php?p=' . ($i * $per_page) . '&order_var='.$order_var.'">'.($i +1). '</a></strong>' :
' <a href="index.php?p=' . ($i * $per_page) . '&order_var='.$order_var.'">'.($i +1). '</a>';
}
When I type in the current code basically nothing changes. The table entries can still be sorted and rated on but there is not pagination. If I change the url to ?p=5 for example then the pagination works appropriately.
So the code works but the for loop is not being executed correctly. The problem might have to do with the fact that not all variables are defined on the index.php page but I tried adding some definitions to make sure that all variables in the for loop are defined on the same page, but it didnt change anything.
Just one last note: the pagination code was working perfectly when I did not use the rating system and had the sql_query and the for loop echoing the page numbers all on the same .php page.
Thank you for your help. I really wish I was better at this stuff
Shibbs