Jump to content

[SOLVED] Pagination Help - Needs Fixin'


Lamez

Recommended Posts

ok, I am still working on my index page, but now I am adding a pagination script I have had, and it worked well, but now I am running into problems.

 

Here is what is happening, I set it to show 4 entrys per page, well it shows no links to any other pages when there are only 4 entys, but when I add another enrty, it shows all 5 on one page, but it shows how many page numbers there are suppose to be. And it does not add the fifth entry to the second page.

 

I have no idea how to fix this one.

 

here is the code:

<?php
$path = "";
$title = "Home";
$ban = "no";
$rank = "yes";
$num = 4;
include ($path."main/include/cons/head.php");
$page = isset($_GET['page']) && is_numeric($_GET['page']) && $_GET['page'] >= 1 ? $_GET['page'] : 1;

$per_page = $num;

$count_q = mysql_query("SELECT COUNT(id) FROM home ORDER BY id DESC");
$count_r = mysql_fetch_row($count_q);
$count = $count_r[0];

if($page > ceil($count/$per_page)) $page = 1;


$limit_min = ($page-1)*$per_page;
$query = mysql_query("SELECT * FROM home ORDER BY id DESC LIMIT {$limit_min}, {$per_page}");



$sql = mysql_query("SELECT * FROM `home` ORDER BY `id` DESC");
   

$num_rows = mysql_num_rows($sql);  

if($num_rows < '1'){
  echo '<p class="header">Welcome</p><p class="maintext">This is the default entry, if you are the admin, please login and add an entry.</p>';
  }


  while($row = mysql_fetch_array($sql)){
  
         echo "<p class=\"header\">".$row['title'];
	 if($session->logged_in){
	 if($session->isAdmin()){

	echo "  <font size='2'><a href=".$path."main/include/dele_top.php?cmd=delete&id=".$row['id'].">Delete Topic(".$row['id'].")</a></font>";

	 }
	 }

         echo "</p><p class=\"maintext\">";
           echo $row['content']; 
         echo "</p>";
  }
  
  
$limit2 = $per_page;

$q = "SELECT id FROM home";
$r = mysql_query($q);
$num = ceil(mysql_num_rows($r) / $limit2);
if($num != 1)
{
  for($i = 1; $i <= $num; $i++)
  {
     

    /*if($page / $limit2 != $i)*/ echo "[<a href='?p=list&page=".$i."'>".$i."</a>] ";
    //else echo "[<b>".$i."</b>] ";
  }
}
include ($path."main/include/cons/foot.php");
?>

Link to comment
https://forums.phpfreaks.com/topic/114199-solved-pagination-help-needs-fixin/
Share on other sites

ha, I fixed it :D

 

<?php
$path = "";
$title = "Home";
$ban = "no";
$rank = "yes";
$num = 4;
include ($path."main/include/cons/head.php");
$page = isset($_GET['page']) && is_numeric($_GET['page']) && $_GET['page'] >= 1 ? $_GET['page'] : 1;

$per_page = $num;

$count_q = mysql_query("SELECT COUNT(id) FROM home ORDER BY id DESC");
$count_r = mysql_fetch_row($count_q);
$count = $count_r[0];

if($page > ceil($count/$per_page)) $page = 1;


$limit_min = ($page-1)*$per_page;
$query = mysql_query("SELECT * FROM home ORDER BY id DESC LIMIT {$limit_min}, {$per_page}");
   
$sql = mysql_query("SELECT * FROM home ORDER BY id DESC");
$num_rows = mysql_num_rows($sql);  
if($num_rows < '1'){
  echo '<p class="header">Welcome</p><p class="maintext">This is the default entry, if you are the admin, please login and add an entry.</p>';
  }


  //while($row = mysql_fetch_array($sql)){
  while($row = mysql_fetch_assoc($query)) {
         echo "<p class=\"header\">".$row['title'];

	 if($session->logged_in){
	 if($session->isAdmin()){
	echo "  <font size='2'><a href=".$path."main/include/dele_top.php?cmd=delete&id=".$row['id'].">Delete Topic(".$row['id'].")</a></font>";
	 }
	 }

         echo "</p><p class=\"maintext\">";
           echo $row['content']; 
         echo "</p>";
  }
  
  
$limit2 = $per_page;

$q = "SELECT id FROM home";
$r = mysql_query($q);
$num = ceil(mysql_num_rows($r) / $limit2);
if($num != 1)
{
  for($i = 1; $i <= $num; $i++)
  {
    /*if($page / $limit2 != $i)*/ echo "[<a href='?p=list&page=".$i."'>".$i."</a>] ";
    //else echo "[<b>".$i."</b>] ";
  }
}
include ($path."main/include/cons/foot.php");
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.