Guest User

Untitled

a guest
Dec 12th, 2016
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.28 KB | None | 0 0
  1. <link href="bootstrap3.css" rel="stylesheet">  
  2. <?php  
  3. $dbhost = 'localhost';  
  4. $dbuser = 'root';  
  5. $dbpass = ";  
  6. $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');  
  7. $dbname = 'test';  
  8. $connection = mysql_select_db($dbname);  
  9.  
  10. $limit = 2;  
  11. if (isset($_GET["page"])) { $page  = $_GET["page"]; } else { $page=1; };  
  12. $start_from = ($page-1) * $limit;  
  13.  
  14. $sql = "SELECT * FROM posts ORDER BY title ASC LIMIT $start_from, $limit";  
  15. $rs_result = mysql_query ($sql);  
  16. ?>  
  17. <table class="table table-bordered table-striped">  
  18. <thead>  
  19. <tr>  
  20. <th>title</th>  
  21. <th>body</th>  
  22. </tr>  
  23. <thead>  
  24. <tbody>  
  25. <?php  
  26. while ($row = mysql_fetch_assoc($rs_result)) {  
  27. ?>  
  28.             <tr>  
  29.             <td><? echo $row["title"]; ?></td>  
  30.             <td><? echo $row["body"]; ?></td>  
  31.             </tr>  
  32. <?php  
  33. };  
  34. ?>  
  35. </tbody>  
  36. </table>  
  37. <?php  
  38. $sql = "SELECT COUNT(id) FROM posts";  
  39. $rs_result = mysql_query($sql);  
  40. $row = mysql_fetch_row($rs_result);  
  41. $total_records = $row[0];  
  42. $total_pages = ceil($total_records / $limit);  
  43. $pagLink = "<div class='pagination'>";  
  44. for ($i=1; $i<=$total_pages; $i++) {  
  45.              $pagLink .= "<a href='index.php?page=".$i."'>".$i."</a>";  
  46. };  
  47. echo $pagLink . "</div>";  
  48. ?>
Add Comment
Please, Sign In to add comment