PHP interesse |
|
Hallo iedereen,
Ik heb zowat alles geprobeerd maar het lukt me nog steeds niet dit pagina nummeringsscript in te bouwen in mijn website.
Ik krijg wel de nummering onderaan mijn pagina en deze zijn ook aanklikbaar maar ik zie op elke pagina dezelfde inhoud (= alle berichten van mijn weblog). Het houdt dus ook geen rekening met de ingevulde hoeveelheid van 10 berichten per pagina.
De code:
<?php $db['host'] = "localhost";
$db['user'] = "gebruikersnaam";
$db['pass'] = "wachtwoord";
$db['name'] = "databasenaam";
$db['prefix'] = "prefix";
$link = mysql_connect($db['host'], $db['user'], $db['pass'])
or die('Could not connect: ' . mysql_error());
mysql_select_db($db['name']) or die('Could not select database');
$result = mysql_query("SELECT * FROM weblog WHERE news_id = 2");
$num_rows = mysql_num_rows($result);
$comments_per_page = 10;
$total_pages = $num_rows / $comments_per_page;
$total_pages = ceil($total_pages);
$total_pages = 10;
$current_page = $_REQUEST['page'];
$etc_points = false;
if ($_REQUEST['page'] == 1) $current = 0;
else $current = $comments_per_page * $_REQUEST['page'] - $comments_per_page;
$max = $current + $comments_per_page;
$result2 = mysql_query("SELECT * FROM weblog LIMIT $current, $comments_per_page");
while ($row = mysql_fetch_array($result2))
{
echo $row['comments_id'] . "<br>";
}
for($i=1;$i<=$total_pages;$i++){
if($i < 3){
echo "<a href=\"?page=".$i."\">" . $i . "</a> ";
$etc_points = true;
continue;
}
if($i > $total_pages - 2){
echo "<a href=\"?page=".$i."\">" . $i . "</a> ";
$etc_points = true;
continue;
}
if(($i >= $current_page - 2) && ($i <= $current_page + 2)){
echo "<a href=\"?page=".$i."\">" . $i . "</a> ";
$etc_points = true;
continue;
}
if($etc_points){
echo " ... ";
$etc_points = false;
continue;
}
}
?>
<?php $db['host'] = "localhost"; $db['user'] = "gebruikersnaam"; $db['pass'] = "wachtwoord"; $db['name'] = "databasenaam"; $db['prefix'] = "prefix"; $result = mysql_query("SELECT * FROM weblog WHERE news_id = 2"); $comments_per_page = 10; $total_pages = $num_rows / $comments_per_page; $total_pages = ceil($total_pages); $total_pages = 10; $current_page = $_REQUEST['page']; $etc_points = false; if ($_REQUEST['page'] == 1) $current = 0; else $current = $comments_per_page * $_REQUEST['page'] - $comments_per_page; $max = $current + $comments_per_page; $result2 = mysql_query("SELECT * FROM weblog LIMIT $current, $comments_per_page"); { echo $row['comments_id'] . "<br>"; } for($i=1;$i<=$total_pages;$i++){ if($i < 3){ echo "<a href=\"?page=".$i."\">" . $i . "</a> "; $etc_points = true; continue; } if($i > $total_pages - 2){ echo "<a href=\"?page=".$i."\">" . $i . "</a> "; $etc_points = true; continue; } if(($i >= $current_page - 2) && ($i <= $current_page + 2)){ echo "<a href=\"?page=".$i."\">" . $i . "</a> "; $etc_points = true; continue; } if($etc_points){ $etc_points = false; continue; } } ?>
|