oto połączony skrypt z paginacja - gdzie paginacja nie działa
<?php require_once("../../includes/initialize.php"); ?> <?php // Find all photos $photos = Photograph::find_all(); ?> <?php // 1. the current page number ($current_page) // 2. records per page ($per_page) $per_page = 5; // 3. total record count ($total_count) $total_count = Photograph::count_all(); // Find all photos //$photos = Photograph::find_all(); $pagination = new Pagination($page, $per_page, $total_count); // Instead of finding all records, just find the records // for this page $sql = "SELECT * FROM photographs "; $sql .= "LIMIT {$per_page} "; $sql .= "OFFSET {$pagination->offset()}"; $photos = Photograph::find_by_sql($sql); // Need to add ?page=$page to all links we want to // maintain the current page (or store $page in $session) ?> <?php foreach($_POST as $key => $value) { if ($key[0] == "remove") { $remove[] = $value; } } } try { $objDB = new PDO('mysql:host=localhost;dbname=dw_bookstore', 'root', '3edcvfr4'); $objDB->exec("SET CHARACTER SET utf8"); $sql = "DELETE FROM `photographs` WHERE `id` IN ("; $sql .= ")"; $statement = $objDB->query($sql); $result = $statement->execute(); } catch(Exception $e) { } } } try { $objDB = new PDO('mysql:host=localhost;dbname=dw_bookstore', 'root', '3edcvfr4'); $objDB->exec("SET CHARACTER SET utf8"); $sql = "SELECT * FROM `photographs` ORDER BY `caption` ASC"; $statement = $objDB->query($sql); $results = $statement->fetchAll(PDO::FETCH_ASSOC); } catch(Exception $e) { } ?> <!DOCTYPE HTML> <html lang="en"> <head> <meta charset="utf-8" /> <title>Remove records with checkboxes</title> <meta name="description" content="Remove records with checkboxes" /> <meta name="keywords" content="Remove records with checkboxes" /> <link href="../../stylesheets/core.css" rel="stylesheet" type="text/css" /> <!--[if lt IE 9]> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> </head> <body> <div id="wrapper"> <form action="" method="post"> <table cellpadding="0" cellspacing="0" border="0" class="tbl_repeat"> <thead> <tr> <th>Filename</th> <th>Caption</th> <th>Caption_2</th> <th class="col1"> <input type="checkbox" class="select-all" id="remove" /> </th> </tr> </thead> <tbody> <?php foreach($results as $row) { ?> <tr> <td> <input type="checkbox" class="remove" </td> </tr> <?php } ?> <?php } else { ?> <tr> <td colspan="4"> There are currently no records available </td> </tr> <?php } ?> <tr> <td colspan="4"> <input type="submit" class="button" value="Update" /> </td> </tr> </tbody> </table> <input type="hidden" name="update" value="1" /> </form> </div> <script src="../../js/jquery-1.6.2.min.js" type="text/javascript"></script> <script src="../../js/core.js" type="text/javascript"></script> <div id="pagination" style="clear: both;"> <?php if($pagination->total_pages() > 1) { if($pagination->has_previous_page()) { } $start = $page - 5; if ($start < 1) $start = 1; $end = $page+5; if ($end > $pagination->total_pages()) $end = $pagination->total_pages(); for($i=$start; $i <= $end; $i++) { if($i == $page) { } else { } } if($pagination->has_next_page()) { } } ?> </div> </body> </html>
dodatkowe funkcje w klasie photograph
// Common Database Methods return self::find_by_sql("SELECT * FROM ".self::$table_name); } $result_array = self::find_by_sql("SELECT * FROM ".self::$table_name." WHERE id=".$database->escape_value($id)." LIMIT 1"); } $result_set = $database->query($sql); while ($row = $database->fetch_array($result_set)) { $object_array[] = self::instantiate($row); } return $object_array; } $sql = "SELECT COUNT(*) FROM ".self::$table_name; $result_set = $database->query($sql); $row = $database->fetch_array($result_set); }