Jump to content

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

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.