Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE HTML>
- <head>
- <meta http-equiv="content-type" content="text/html" />
- <title>test</title>
- <script src="http://code.jquery.com/jquery-latest.js"></script>
- </head>
- <body>
- <?php
- $db_host = "127.0.0.1";
- $db_user = 'root';
- $db_password = '';
- $db_name = '3';
- mysql_connect($db_host, $db_user, $db_password) or die (mysql_error());
- mysql_select_db($db_name) or die (mysql_error());
- mysql_query("SET NAMES 'utf8'");
- $num_elements = 20;
- $total = mysql_result(mysql_query("SELECT COUNT(*) FROM articles"),0,0);
- $num_pages = ceil($total / $num_elements);
- if(!isset($_GET['page'])){
- $p = 1;
- }
- else{
- $p = addslashes(strip_tags(trim($_GET['page'])));
- if($p < 1) $p = 1;
- }
- if ($p > $num_pages) $p = $num_pages;
- $start = ($p - 1) * $num_elements;
- $sql = mysql_query("SELECT * FROM articles ORDER BY id DESC LIMIT ".$start.", ".$num_elements);
- function GetNav($p, $num_pages){
- if($p > 2){
- $first_page = ' <a href="/index.php?page=1"><<</a> '; //или просто $first_page = ' <a href="/index.php"><<</a> ';
- }
- else{
- $first_page = '';
- }
- if($p < ($num_pages - 2)){
- $last_page = ' <a href="/index.php?page='.$num_pages.'">>></a> ';
- }
- else{
- $last_page = '';
- }
- if($p > 1){
- $prev_page = ' <a href="/index.php?page='.($p - 1).'"><</a> ';
- }
- else{
- $prev_page = '';
- }
- if($p < $num_pages){
- $next_page = ' <a href="/index.php?page='.($p + 1).'">></a> ';
- }
- else{
- $next_page = '';
- }
- if($p - 2 > 0){
- $prev_2_page = ' <a href="/index.php?page='.($p - 2).'">'.($p - 2).'</a> ';
- }
- else{
- $prev_2_page = '';
- }
- if($p - 1 > 0){
- $prev_1_page = ' <a href="/index.php?page='.($p - 1).'"> '.($p - 1).' </a> ';
- }
- else{
- $prev_1_page = '';
- }
- if($p + 2 <= $num_pages){
- $next_2_page = ' <a href="/index.php?page='.($p + 2).'"> '.($p + 2).' </a> ';
- }
- else{
- $next_2_page = '';
- }
- if($p + 1 <= $num_pages){
- $next_1_page = ' <a href="/index.php?page='.($p + 1).'">'.($p + 1).'</a> ';
- }
- else{
- $next_1_page = '';
- }
- $nav = $first_page.$prev_page.$prev_2_page.$prev_1_page.$p.$next_1_page.$next_2_page.$next_page.$last_page;
- return $nav;
- }
- ?>
- <div id="load">
- <div class="posts"><?php while ($sql_data = mysql_fetch_array($sql)) {
- echo $sql_data['title'];
- echo '<br />';
- echo $sql_data['text'];
- echo '<br /><br />';
- }?></div>
- <div class="nav"><?php echo GetNav($p, $num_pages);?></div>
- </div>
- <script type="text/javascript">
- <!--
- $(function() {
- $(".nav a").click(function() {
- var link = $(this).attr("href");
- $("#load").hide();
- $("body").load(link);
- return false;
- });
- });
- -->
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement