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
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");
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.