paginanummers

Gesponsorde koppelingen

PHP script bestanden

  1. paginanummers

« Lees de omschrijving en reacties

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
$table
= "replies";
$sql_count = "SELECT COUNT(id) FROM $table WHERE nid = '$_GET[id]'";    // Count the number of posts
$res_count = mysql_query($sql_count);
$total_posts = mysql_result($res_count, 0);

$posts = isset($_GET['posts']) ? $_GET['posts'] : 0;
$per_page = 5;   // Set the amount of posts per page

$sql_replies = "SELECT * FROM $table WHERE nid = '$_GET[id]' ORDER BY id DESC LIMIT $posts, $per_page";   // Select posts where the limit is set using variables
$res_replies = mysql_query($sql_replies);
if (mysql_num_rows($res_replies) >= 1) {
    while ($row_replies = mysql_fetch_array($res_replies)) {
        echo "<p>".$row_replies['message']."</p>";
        }

    echo pagenumbers($total_posts, $per_page);
    }

function
pagenumbers($total_posts, $per_page) {
    $pages = 0;   // Set initial amount of pages
    $posts = 0;   // Set initial amount of posts
    $num = $total_posts / $per_page;   // Get amount of pages
    $num = ceil($num);
    if ($num >= 2) {   // Set the amount of pages at wich to start numbering
        echo "<b>";
        while ($pages < $num) {   // Check if current page is less as amount of $pages
            $pages ++;   // Add 1 to page
            if ($posts == $_GET['posts']) {   // Check if current page equals $posts so it isn't a link
                $links = $pages." ";
                }

            else {   // Set pagenumber as a link
                $links = "<a href=\"$_SERVER[PHP_SELF]?page=$_GET[page]&id=$_GET[id]&posts=$posts\">".$pages." </a>";
                }

            echo $links;   // Display link
            if ($pages < $num) {   // Check if current page is less as amount of $pages
                echo " : ";   // Set the divider between the pagenumbers
                }
            $posts = $posts + $per_page;   // Set the modifier for $posts
            }
        echo "</b>";
        }
    }

?>

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.