<?php
$npp = "10";
$begin = mysql_query("SELECT * FROM tpnieuws ORDER BY id DESC LIMIT 0, ".$npp) OR DIE(mysql_error());
while($row = mysql_fetch_array($begin))
{
echo "<a href=\"".$_SERVER['PHP_SELF']."?item=".$row['id']."\"><b><i>".$row['titel']."</i></b></a> - <i>".$row['datum']."</i><br /><br />";
}
echo "<br />";
//Eerst delen we het totaal aantal pagina's door het aantal nieuwsberichten per pagina.
$nieuwepagina = $aantal / $npp;
//Daarna ronden we het af naar boven. Functie: ceil. http://www.phphulp.nl/php/tutorials/1/106/186/
$nieuwepagina = ceil($nieuwepagina);
echo "Pagina: ";
//P 1 sette en dan steeds hoger optellen zodat de nummer chronologisch blijven!
$p = 1;
for($i=$nieuwepagina; $i > 0;$i--)
{
if($p == 1)
{
echo "<a href=\"".$_SERVER['PHP_SELF']."?p=".$p."\"><b>$p</b></a>";
}
else
{
echo "<a href=\"".$_SERVER['PHP_SELF']."?p=".$p."\">$p</a>";
}
$p++;
}
?>
Maar als je verder gaat kijken werken de volgende pagina's niet goed. Hij pakt wel steeds goed de eerste limit maar de 2e werkt niet echt. Hier de code die bij het stuk hoort als er een GET p is.
<?php
$npp = "10";
if(isset($_GET['p']))
{
echo "<font size=\"2\"><a href=\"".$_SERVER['PHP_SELF']."\"><b>Nieuws</b></a></font><hr style=\"color: #000000;\" /><br />";
//Dan bestaat er een pagina nummer! :)
$p = $_GET['p'];
//Maximaal in de limit statement in de SQL.
$maximaal = $p * $npp;
//Minimaal in de limit statement in de SQL.
$minimaal = $maximaal - $npp;
$sql = mysql_query("SELECT * FROM tpnieuws ORDER BY id DESC LIMIT ".$minimaal.", ".$maximaal." ") OR DIE(mysql_error());
while($row = mysql_fetch_array($sql))
{
echo "<a href=\"".$_SERVER['PHP_SELF']."?item=".$row['id']."\"><b><i>".$row['titel']."</i></b></a> - <i>".$row['datum']."</i><br /><br />";
}
//Pagina nummering
$pagina = mysql_query("SELECT * FROM tpnieuws ORDER BY id DESC") OR DIE(mysql_error());
$aantal = mysql_num_rows($pagina);
echo "<br />";
//Eerst delen we het totaal aantal pagina's door het aantal nieuwsberichten per pagina.
$nieuwepagina = $aantal / $npp;
//Daarna ronden we het af naar boven. Functie: ceil. http://www.phphulp.nl/php/tutorials/1/106/186/
$nieuwepagina = ceil($nieuwepagina);
echo "Pagina: ";
//P 1 sette en dan steeds hoger optellen zodat de nummer chronologisch blijven!
$pn = 1;
for($i=$nieuwepagina; $i > 0;$i--)
{
if($p == $pn)
{
echo "<a href=\"".$_SERVER['PHP_SELF']."?p=".$pn."\"><b>$pn</b></a>";
}
else
{
echo "<a href=\"".$_SERVER['PHP_SELF']."?p=".$pn."\">$pn</a>";
}
$pn++;
}
}
?>
Wie o wie helpt mij uit de brand?