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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
| <?php
// Pour pagination - Etape 1 - Détermination du nombre d'enregistrements maximum à afficher par page
$limit=500;
$servername = "host";
$username = "user";
$password = "password";
$dbname = "db";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
// Requête SQL
$sql = 'SELECT * FROM monuments'
. ' WHERE PAYS = "BE"'
. ' ORDER BY CITY, ZIP, MON_USUEL ';
// Pour pagination - Etape 2
$numresults=mysqli_query($conn, $sql);
$numrows=mysqli_num_rows($numresults);
// next determine if s has been passed to script, if not use 0
if (empty($s)) {
$s=0;
}
// get results
$sql .= " limit $s,$limit";
// Envoi de la requête SQL
$result = mysqli_query($conn, $sql);
$a = $s + ($limit) ;
if ($a > $numrows) { $a = $numrows ; }
$b = $s + 1 ;
echo "<p><b>Résultats - Resultaten: $b - $a / $numrows</b></p>";
// Pour pagination - Etape 3 - Affichage des strings suivants - précédents
$count = 1 + $s ;
// next we need to do the links to other results
if ($s>=1) { // bypass PREV link if s is 0
$prevs=($s-$limit);
print " <a href=\"$_PHP_SELF?s=$prevs&q=$var\">
500 monuments précédents - vorige 500 gedenktekens</a>  ";
}
// calculate number of pages needing links
$pages=intval($numrows/$limit);
// $pages now contains int of pages needed unless there is a remainder from division
if ($numrows%$limit) {
// has remainder so add one page
$pages++;
}
// check to see if last page
if (!((($s+$limit)/$limit)==$pages) && $pages!=1) {
// not last page so give NEXT link
$news=$s+$limit;
echo " <a href=\"$_PHP_SELF?s=$news&q=$var\">500 monuments suivants - volgende 500 gedenktekens </a>";
}
//break before paging
echo "<br /><br />";
// Envoi de la requête SQL
$result = mysqli_query($conn, $sql);
// Affichage du résultat
while ($voir = mysqli_fetch_array($result))
{
// on affiche les informations de l'enregistrement en cours
echo"".$voir[CITY]." (".$voir[ZIP]."), <a href=".$voir[MON_URL].">".$voir[MON_USUEL]."</a>
<br>";
}
// Pour pagination - Etape 3 - Affichage des strings suivants - précédents
$count = 1 + $s ;
//break before paging
echo "<br />";
// next we need to do the links to other results
if ($s>=1) { // bypass PREV link if s is 0
$prevs=($s-$limit);
print " <a href=\"$_PHP_SELF?s=$prevs&q=$var\">
500 monuments précédents - vorige 500 gedenktekens</a>  ";
}
// calculate number of pages needing links
$pages=intval($numrows/$limit);
// $pages now contains int of pages needed unless there is a remainder from division
if ($numrows%$limit) {
// has remainder so add one page
$pages++;
}
// check to see if last page
if (!((($s+$limit)/$limit)==$pages) && $pages!=1) {
// not last page so give NEXT link
$news=$s+$limit;
echo " <a href=\"$_PHP_SELF?s=$news&q=$var\">500 monuments suivants - volgende 500 gedenktekens </a>";
}
$a = $s + ($limit) ;
if ($a > $numrows) { $a = $numrows ; }
$b = $s + 1 ;
echo "<p><b>Résultats - Resultaten: $b - $a / $numrows</b></p>";
// Fermeture de la base MySQL
mysqli_close();
?> |
Partager