Jump to content

[SOLVED] Pagination - Where am I going wrong?


mark110384

Recommended Posts

I'm currently trying to implement pagination into my web forum but it just doesn't seem to work. Currently a user selects a thread to view and the results are displayed as topics. The topics displayed refer to the thread selected, so for example thread 5 with bring back all the topics with the thread id 5 stored along side it. So I would imagine I would have to send the thread_id (throught the url) every time a page selected. Below are snippets of the code.

 

$thread_no = $_GET["thread_selected"];


if (!(isset($pageno)))
{
$pageno = 1;
} 

 

 

$sql_count_pag = "SELECT * FROM forum_topic WHERE thread_ID = '$thread_no'";

			$result_pag_count = mysql_query($sql_count_pag) or die  ("Data not found");

			$numrows = mysql_num_rows($result_pag_count);

$rows_per_page = 5;
$lastpage      = ceil($numrows/$rows_per_page);


if ($pageno < 1)
{
$pageno = 1;
}
elseif ($pageno > $lastpage)
{
$pageno = $lastpage;
} 

$limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page;



$sql = "SELECT * FROM forum_topic WHERE thread_ID = '$thread_no' ORDER BY last_update DESC $limit";

 

 

And the navigation

 

echo " ( Page $pageno of $lastpage ) ";

if ($pageno == 1)
{
}
else
{
echo " <a href='{$_SERVER['PHP_SELF']}?thread_selected=$thread_no&pagenum=1'> <<-First</a> ";
echo " ";
$prevpage = $pageno-1;
echo " <a href='{$_SERVER['PHP_SELF']}?thread_selected=$thread_no&pagenum=$prevpage'> <-Previous</a> ";
}



if ($pageno == $lastpage)
{
}
else {
$nextpage = $pageno+1;
echo " <a href='{$_SERVER['PHP_SELF']}?thread_selected=$thread_no&pagenum=$nextpage'>Next -></a> ";
echo " ";
echo " <a href='{$_SERVER['PHP_SELF']}?thread_selected=$thread_no&pagenum=$lastpage'>Last ->></a> ";

 

At the moment the results remain the same in the table but the pagenum in the url changes to 2 when you hit next and then if you hit it again does nothing? Any suggestions would be greatly appreciated thank you

HUmmm

this line gets the thread

$sql = "SELECT * FROM forum_topic WHERE thread_ID = '$thread_no' ORDER BY last_update DESC $limit";

but you only use $thread_no + 1 so if you delete a forum topic your get holes (the thread won't exist)

 

i guess this is what your getting now..

may i suggect trying

$sql = "SELECT * FROM forum_topic ORDER BY last_update DESC  LIMIT $thread_no, 1

 

i removed you $limit as i don't know what it does ( i could guess )

 

EDIT: i sould point out that the example above will need tweaking but should give you the basic idea

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.