Znalazłem na tej stronie http://www.ssdtutorials.com/tutorials/seri...checkboxes.html fajny tutorial do usuwania wielu rekordów, próbuje go połączyć z paginacją od wczoraj ale nic mi nie wychodzi, gdyby ktoś chciałby mi pomóc byłbym bardzo szczęśliwy, z góry dziękuję za pomoc.

oto połączony skrypt z paginacja - gdzie paginacja nie działa

  1. <?php require_once("../../includes/initialize.php"); ?>
  2.  
  3. <?php
  4. // Find all photos
  5. $photos = Photograph::find_all();
  6. ?>
  7.  
  8.  
  9.  
  10. <?php
  11.  
  12. // 1. the current page number ($current_page)
  13. $page = !empty($_GET['page']) ? (int)$_GET['page'] : 1;
  14.  
  15. // 2. records per page ($per_page)
  16. $per_page = 5;
  17.  
  18. // 3. total record count ($total_count)
  19. $total_count = Photograph::count_all();
  20.  
  21.  
  22. // Find all photos
  23. //$photos = Photograph::find_all();
  24.  
  25. $pagination = new Pagination($page, $per_page, $total_count);
  26.  
  27. // Instead of finding all records, just find the records
  28. // for this page
  29. $sql = "SELECT * FROM photographs ";
  30. $sql .= "LIMIT {$per_page} ";
  31. $sql .= "OFFSET {$pagination->offset()}";
  32. $photos = Photograph::find_by_sql($sql);
  33.  
  34. // Need to add ?page=$page to all links we want to
  35. // maintain the current page (or store $page in $session)
  36.  
  37.  
  38.  
  39. ?>
  40.  
  41.  
  42.  
  43. <?php
  44. if (isset($_POST['update']) && $_POST['update'] == 1) {
  45.  
  46. $remove = array();
  47.  
  48. foreach($_POST as $key => $value) {
  49. $key = explode("_", $key);
  50. if (is_array($key) && count($key) > 1) {
  51. if ($key[0] == "remove") {
  52. $remove[] = $value;
  53. }
  54. }
  55. }
  56.  
  57. if (!empty($remove)) {
  58.  
  59. try {
  60.  
  61. $objDB = new PDO('mysql:host=localhost;dbname=dw_bookstore', 'root', '3edcvfr4');
  62. $objDB->exec("SET CHARACTER SET utf8");
  63.  
  64. $sql = "DELETE FROM `photographs`
  65. WHERE `id` IN (";
  66. $sql .= implode(", ", $remove);
  67. $sql .= ")";
  68.  
  69. $statement = $objDB->query($sql);
  70. $result = $statement->execute();
  71.  
  72. } catch(Exception $e) {
  73. echo 'There was a problem with the database';
  74. }
  75.  
  76. }
  77.  
  78. }
  79.  
  80. try {
  81.  
  82. $objDB = new PDO('mysql:host=localhost;dbname=dw_bookstore', 'root', '3edcvfr4');
  83. $objDB->exec("SET CHARACTER SET utf8");
  84.  
  85. $sql = "SELECT *
  86. FROM `photographs`
  87. ORDER BY `caption` ASC";
  88.  
  89. $statement = $objDB->query($sql);
  90. $results = $statement->fetchAll(PDO::FETCH_ASSOC);
  91.  
  92.  
  93. } catch(Exception $e) {
  94. echo 'There was a problem with the database';
  95. }
  96.  
  97. ?>
  98. <!DOCTYPE HTML>
  99. <html lang="en">
  100. <head>
  101. <meta charset="utf-8" />
  102. <title>Remove records with checkboxes</title>
  103. <meta name="description" content="Remove records with checkboxes" />
  104. <meta name="keywords" content="Remove records with checkboxes" />
  105. <link href="../../stylesheets/core.css" rel="stylesheet" type="text/css" />
  106. <!--[if lt IE 9]>
  107. <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
  108. <![endif]-->
  109. </head>
  110. <body>
  111.  
  112. <div id="wrapper">
  113.  
  114. <form action="" method="post">
  115. <table cellpadding="0" cellspacing="0" border="0" class="tbl_repeat">
  116. <thead>
  117. <tr>
  118. <th>Filename</th>
  119. <th>Caption</th>
  120. <th>Caption_2</th>
  121. <th class="col1">
  122. <input type="checkbox" class="select-all" id="remove" />
  123. </th>
  124. </tr>
  125. </thead>
  126. <tbody>
  127. <?php if (!empty($results)) { ?>
  128. <?php foreach($results as $row) { ?>
  129. <tr>
  130. <td><?php echo $row['filename']; ?></td>
  131. <td><?php echo $row['caption']; ?></td>
  132. <td><?php echo $row['caption_2']; ?></td>
  133. <td>
  134. <input type="checkbox" class="remove"
  135. name="remove_<?php echo $row['id']; ?>"
  136. id="remove_<?php echo $row['id']; ?>"
  137. value="<?php echo $row['id']; ?>" />
  138. </td>
  139. </tr>
  140. <?php } ?>
  141. <?php } else { ?>
  142. <tr>
  143. <td colspan="4">
  144. There are currently no records available
  145. </td>
  146. </tr>
  147. <?php } ?>
  148. <tr>
  149. <td colspan="4">
  150. <input type="submit" class="button" value="Update" />
  151. </td>
  152. </tr>
  153. </tbody>
  154. </table>
  155. <input type="hidden" name="update" value="1" />
  156. </form>
  157.  
  158. </div>
  159.  
  160.  
  161. <script src="../../js/jquery-1.6.2.min.js" type="text/javascript"></script>
  162. <script src="../../js/core.js" type="text/javascript"></script>
  163.  
  164.  
  165.  
  166.  
  167. <div id="pagination" style="clear: both;">
  168. <?php
  169. if($pagination->total_pages() > 1) {
  170.  
  171. if($pagination->has_previous_page()) {
  172. echo "<a href=\"delete_photo_3_A1.php?page=";
  173. echo $pagination->previous_page();
  174. echo "\">&laquo; Previous</a> ";
  175. }
  176.  
  177. $start = $page - 5;
  178. if ($start < 1) $start = 1;
  179. $end = $page+5;
  180. if ($end > $pagination->total_pages()) $end = $pagination->total_pages();
  181.  
  182. for($i=$start; $i <= $end; $i++) {
  183. if($i == $page) {
  184. echo " <span class=\"selected\">{$i}</span> ";
  185. } else {
  186. echo " <a href=\"delete_photo_3_A1.php?page={$i}\">{$i}</a> ";
  187. }
  188. }
  189.  
  190. if($pagination->has_next_page()) {
  191. echo " <a href=\"delete_photo_3_A1?page=";
  192. echo $pagination->next_page();
  193. echo "\">Next &raquo;</a> ";
  194. }
  195.  
  196. }
  197.  
  198. ?>
  199. </div>
  200. </body>
  201. </html>
  202.  


dodatkowe funkcje w klasie photograph

  1. // Common Database Methods
  2. public static function find_all() {
  3. return self::find_by_sql("SELECT * FROM ".self::$table_name);
  4. }
  5.  
  6. public static function find_by_id($id=0) {
  7. global $database;
  8. $result_array = self::find_by_sql("SELECT * FROM ".self::$table_name." WHERE id=".$database->escape_value($id)." LIMIT 1");
  9. return !empty($result_array) ? array_shift($result_array) : false;
  10. }
  11.  
  12. public static function find_by_sql($sql="") {
  13. global $database;
  14. $result_set = $database->query($sql);
  15. $object_array = array();
  16. while ($row = $database->fetch_array($result_set)) {
  17. $object_array[] = self::instantiate($row);
  18. }
  19. return $object_array;
  20. }
  21.  
  22. public static function count_all() {
  23. global $database;
  24. $sql = "SELECT COUNT(*) FROM ".self::$table_name;
  25. $result_set = $database->query($sql);
  26. $row = $database->fetch_array($result_set);
  27. return array_shift($row);
  28. }
  29.