1. <html>
  2. <head>
  3. <link rel="stylesheet" type="text/css" media="all" href="css/jquery.ias.css" />
  4. <script type='text/javascript' src='http://code.jquery.com/jquery-1.4.4.js'></script>
  5. <script type="text/javascript" src="jquery.ias.js"></script>
  6. <script type="text/javascript">
  7. jQuery.ias({
  8. scrollContainer:'#container',
  9. container : '#container',
  10. item: '.item',
  11. pagination: '.pagination',
  12. next: '.nextpage',
  13. loader: '<img src="images/loader.gif"/>'
  14. });
  15. </script>
  16. <style>
  17. div.pagination {
  18. padding: 3px;
  19. margin: 3px;
  20. }
  21. div.pagination a {
  22. padding: 2px 5px 2px 5px;
  23. margin: 2px;
  24. border: 1px solid #AAAADD;
  25. text-decoration: none; /* no underline */
  26. color: #000099;
  27. }
  28. div.pagination a:hover, div.pagination a:active {
  29. border: 1px solid #000099;
  30. color: #000;
  31. }
  32. div.pagination span.current {
  33. padding: 2px 5px 2px 5px;
  34. margin: 2px;
  35. border: 1px solid #000099;
  36. font-weight: bold;
  37. background-color: #000099;
  38. color: #FFF;
  39. }
  40. div.pagination span.disabled {
  41. padding: 2px 5px 2px 5px;
  42. margin: 2px;
  43. border: 1px solid #EEE;
  44. color: #DDD;
  45. }
  46. </style>
  47. </head>
  48. <body>
  49. <?php
  50. $con = mysql_connect("hostname","database","password");
  51. if (!$con)
  52. {
  53. die('Could not connect: ' . mysql_error());
  54. }
  55. mysql_select_db("database", $con);
  56. /*include 'pag.php'; //pagination script and styling is located here.*/
  57. $tbl_name="ticka_data"; //your table name
  58. // How many adjacent pages should be shown on each side?
  59. $adjacents = 3;
  60. /*
  61. First get total number of rows in data table.
  62. If you have a WHERE clause in your query, make sure you mirror it here.
  63. */
  64. $query = "SELECT COUNT(*) as num FROM $tbl_name";
  65. $total_pages = mysql_fetch_array(mysql_query($query));
  66. $total_pages = $total_pages[num];
  67. /* Setup vars for query. */
  68. $targetpage = "pagination2.php"; //your file name (the name of this file)
  69. $limit = 10; //how many items to show per page
  70. $page = $_GET['page'];
  71. if($page)
  72. $start = ($page - 1) * $limit; //first item to display on this page
  73. else
  74. $start = 0; //if no page var is given, set start to 0
  75. /* Get data. */
  76. $sql = "SELECT title FROM $tbl_name LIMIT $start, $limit";
  77. $result = mysql_query($sql);
  78. /* Setup page vars for display. */
  79. if ($page == 0) $page = 1; //if no page var is given, default to 1.
  80. $prev = $page - 1; //previous page is page - 1
  81. $next = $page + 1; //next page is page + 1
  82. $lastpage = ceil($total_pages/$limit); //lastpage is = total pages / items per page, rounded up.
  83. $lpm1 = $lastpage - 1; //last page minus 1
  84. /*
  85. Now we apply our rules and draw the pagination object.
  86. We're actually saving the code to a variable in case we want to draw it more than once.
  87. */
  88. $pagination = "";
  89. if($lastpage > 1)
  90. {
  91. $pagination .= "<div class=\"pagination\">";
  92. //previous button
  93. if ($page > 1)
  94. $pagination.= "<a href=\"$targetpage?page=$prev\"> &lsaquo;&lsaquo; previous</a>";
  95. else
  96. $pagination.= "<span class=\"disabled\"> &lsaquo;&lsaquo; previous</span>";
  97. //pages
  98. if ($lastpage < 7 + ($adjacents * 2)) //not enough pages to bother breaking it up
  99. {
  100. for ($counter = 1; $counter <= $lastpage; $counter++)
  101. {
  102. if ($counter == $page)
  103. $pagination.= "<span class=\"current\">$counter</span>";
  104. else
  105. $pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";
  106. }
  107. }
  108. elseif($lastpage > 5 + ($adjacents * 2)) //enough pages to hide some
  109. {
  110. //close to beginning; only hide later pages
  111. if($page < 1 + ($adjacents * 2))
  112. {
  113. for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
  114. {
  115. if ($counter == $page)
  116. $pagination.= "<span class=\"current\">$counter</span>";
  117. else
  118. $pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";
  119. }
  120. $pagination.= "...";
  121. $pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>";
  122. $pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>";
  123. }
  124. //in middle; hide some front and some back
  125. elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
  126. {
  127. $pagination.= "<a href=\"$targetpage?page=1\">1</a>";
  128. $pagination.= "<a href=\"$targetpage?page=2\">2</a>";
  129. $pagination.= "...";
  130. for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
  131. {
  132. if ($counter == $page)
  133. $pagination.= "<span class=\"current\">$counter</span>";
  134. else
  135. $pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";
  136. }
  137. $pagination.= "...";
  138. $pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>";
  139. $pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>";
  140. }
  141. //close to end; only hide early pages
  142. else
  143. {
  144. $pagination.= "<a href=\"$targetpage?page=1\">1</a>";
  145. $pagination.= "<a href=\"$targetpage?page=2\">2</a>";
  146. $pagination.= "...";
  147. for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
  148. {
  149. if ($counter == $page)
  150. $pagination.= "<span class=\"current\">$counter</span>";
  151. else
  152. $pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";
  153. }
  154. }
  155. }
  156. //next button
  157. if ($page < $counter - 1)
  158. $pagination.= "<div class=\"nextpage\"><a href=\"$targetpage?page=$next\">next &rsaquo;&rsaquo;</a></div>";
  159. else
  160. $pagination.= "<span class=\"disabled\">next &rsaquo;&rsaquo;</span>";
  161. $pagination.= "</div>\n";
  162. }
  163. ?>
  164. <div id="container" style="height: 100px;
  165. overflow: scroll;">
  166. <?php
  167. while($row = mysql_fetch_array($result))
  168. {
  169. echo "<div class='item'><li>".$row[0]."</li></div>";
  170. // Your while loop here
  171. }
  172. ?>
  173. </div>
  174. <?=$pagination?>
  175. </body>
  176. </html>