login  Naam:   Wachtwoord: 
Registreer je!
 Scripts:

Scripts > PHP > Navigatie systemen > Paginanavigatie zoals Sitemasters

Paginanavigatie zoals Sitemasters

Auteur: Frederic - 17 maart 2005 - 20:56 - Gekeurd door: Joel - Hits: 9882 - Aantal punten: 3.30 (5 stemmen)




Aangezien ik de navigatie van SM (het forum, news.,..) me wel erg praktisch leek, heb ik geprobeerd dit na te maken adhv een tutorial

Hoe werkt het?
alles declareren
include "navigatie.php";

Query instellen (gastenboek = tabel waaruit het moet komen, 8= standaard aantal berichten per pagina)
navigatie('gastenboek',8);

Navigatie tonen dmv
<? navigatietonen(); ?>

Zo moet de code van de weergavequery komen (LIMIT $offset, $aantal_items_per_pagina)
$sql = "SELECT * FROM gastenboek ORDER BY id DESC LIMIT $offset, $aantal_items_per_pagina";

Code:
  1. <?php
  2. include_once "connect.php";
  3.  
  4.  
  5.  
  6. function correctURL($negeren) {
  7. $querystring = "?"; // de querystring
  8. if(sizeof($_GET) > 1 || !in_array($negeren, array_keys($_GET))) {
  9. // meer queryvariabelen te onthouden dan enkel $_GET[$nav_var]
  10. foreach($_GET as $k => $v) {
  11. if($k != $negeren) {
  12. $querystring .= $k."=".$v."&amp;";
  13. }
  14. }
  15. }
  16. return $querystring;
  17. }
  18.  
  19.  
  20.  
  21.  
  22. function navigatie($op, $max)
  23. {
  24. if (isset($_GET['aantal']) && (($_GET['aantal'] == 8) || ($_GET['aantal'] == 10) || ($_GET['aantal'] == 15) || ($_GET['aantal'] == 20)) && is_numeric($_GET['aantal'])) //Juiste vorm controlen
  25. {
  26. $max = $_GET['aantal']; //Als het OK is, $max instellen
  27. }
  28. global $aantal_items_per_pagina;
  29. global $offset;
  30. global $huidige_pagina;
  31. global $aantal_paginas;
  32. $sql1 = mysql_query("SELECT COUNT(id) FROM ".$op) or die("SQL1:". mysql_error());
  33. $totaal_aantal = mysql_result($sql1, 0);
  34. $aantal_items_per_pagina = $max;
  35. $aantal_paginas = ceil($totaal_aantal / $aantal_items_per_pagina);
  36. $aantal_paginas+=1;
  37. $huidige_pagina = 0;
  38. if(isset($_GET['navigatiepagina']) && is_numeric($_GET['navigatiepagina']) && $_GET['navigatiepagina'] > 0 && $_GET['navigatiepagina'] < $aantal_paginas) {
  39. $huidige_pagina = $_GET['navigatiepagina'];
  40. $huidige_pagina-=1;
  41. }
  42. $offset = $huidige_pagina * $aantal_items_per_pagina;
  43. }
  44.  
  45.  
  46.  
  47.  
  48.  
  49. function navigatietonen()
  50. {
  51. global $huidige_pagina;
  52. global $aantal_paginas;
  53. $plaats = $_SERVER['PHP_SELF'].correctURL("navigatiepagina"); //URL nakijken (met var's enzo)
  54. ?>
  55. <form name="navigatie" action="<? echo $_SERVER['PHP_SELF'] ;?>" method="post">
  56. <?php if ($huidige_pagina != 0) //De terugknoppen
  57. {
  58. ?>
  59. <input name="button" type="button" class="navigatie" onClick="window.location='<? echo $plaats ;?>navigatiepagina=1'" value="<<" />
  60. <input name="button" type="button" class="navigatie" onClick="window.location='<? echo $plaats ;?>navigatiepagina=<? echo $huidige_pagina ;?>'" value="<" />
  61. <?php
  62. }
  63. ?>
  64. <select onChange="window.location=''+this.form.elements['navigatiebox'].value;" name="navigatiebox">
  65. <?php
  66. for($i=1; $i < $aantal_paginas; $i++) //Selectbox
  67. {
  68. ?>
  69. <option value="<? echo $plaats ;?>navigatiepagina=<? echo $i ;?>"<?= ($i - 1 == $huidige_pagina) ? " selected=\"selected\"" : "" ?>><? echo $i ;?></option>
  70. <?
  71. }
  72. ?>
  73. </select>
  74. <?php
  75. if ($huidige_pagina != $aantal_paginas - 2) //De vooruitknoppen
  76. {
  77. ?>
  78. <input name="button" type="button" class="navigatie" onClick="window.location='<? echo $plaats ;?>navigatiepagina=<? echo $huidige_pagina + 2 ;?>'" value=">" />
  79. <input name="button" type="button" class="navigatie" onClick="window.location='<? echo $plaats ;?>navigatiepagina=<? echo $aantal_paginas - 1 ;?>'" value=">>" />
  80. <?php
  81. }
  82. ?>
  83. <br>
  84. <select name="aantal" onChange="window.location=''+this.form.elements['aantal'].value;">
  85. <option value="<? echo $plaats ;?>navigatiepagina=<? echo $huidige_pagina + 1 ;?>">- Aantal: -</option>
  86. <?php
  87. $max = $_GET['aantal']; //Aantallen selecteren (aantal hier aanpassen ==> bovenaan ook aanpassen)
  88. ?>
  89. <option value="?navigatiepagina=1&aantal=8"<?= ($max == 8) ? " selected=\"selected\"" : "" ?>>8 berichten</option>
  90. <option value="?navigatiepagina=1&aantal=10"<?= ($max == 10) ? " selected=\"selected\"" : "" ?>>10 berichten</option>
  91. <option value="?navigatiepagina=1&aantal=15"<?= ($max == 15) ? " selected=\"selected\"" : "" ?>>15 berichten</option>
  92. <option value="?navigatiepagina=1&aantal=20"<?= ($max == 20) ? " selected=\"selected\"" : "" ?>>20 berichten</option>
  93. </select>
  94. </form>
  95. <?php
  96. }
  97. ?>
Download code! Download code (.txt)

 Bekijk een voorbeeld van dit script!
 Stemmen
Niet ingelogd.

 Reacties
Post een reactie
Lees de reacties (3)
© 2002-2024 Sitemasters.be - Regels - Laadtijd: 0.047s