Jump to content

pagination trouble


simmsy

Recommended Posts

Hey everyone im having a little trouble with my forum pagination on the replies. I am using the the id of the topic as the page so this is what it looks like for the link:

" echo "  <tr><td height='50' align='center' valign='top' bgcolor='#AAAAAA'><b>$username</b><br />$date<br />$time</td>

  <td height='50' align='center' bgcolor='#AAAAAA'><b><a href='viewtopic.php?id=$id'>$topic</a></b></td></tr>";"

so the link is http://...........viewtopic.php?id=1

I am using this pagination

  <?

//display data

$get = mysql_query("SELECT * FROM reply WHERE reply_id='$id' LIMIT $start, $per_page");

while ($row = mysql_fetch_assoc($get))

  {

//get data

$a_username = $row['a_username'];

$a_date = $row['a_date'];

$a_time = $row['a_time'];

$a_reply = $row['a_reply'];

 

echo "  <tr><td height='50' align='center' valign='top' bgcolor='#AAAAAA'><b>$a_username</b><br />$a_date<br />$a_time</td>

  <td height='50' align='center' bgcolor='#AAAAAA'>$a_reply</td></tr>";

 

  }

 

  ?>

 

  </table>

  <p />

 

  <div align='center'>

  <?

//setup prev and next variables

$prev = $start - $per_page;

$next = $start + $per_page;

 

//show prev button

if (!($start<=0))

echo "<a href='viewtopic.php?start=$prev'>Prev</a> ";

 

//show page numbers

 

//set variable for first page

$i=1;

 

for ($x=0;$x<$record_count;$x=$x+$per_page)

{

if ($start!=$x)

echo "<a href='viewtopic.php?start=$x'>$i</a> ";

else

echo "<a href='viewtopic.php?start=$x'><b>$i</b></a> ";

$i++;

}

 

//show next button

if (!($start>=$record_count - $per_page))

echo " <a href='viewtopic.php?start=$next'>Next</a>";

 

?>

 

but then when I click on the next page or one of those links it comes out like this http://...........viewtopic.php?id=1?start=2

then click it again http://...........viewtopic.php?id=1?start=2?start=2 and adds that every time I click it

can anyone help its the last part of making my forum, please?

Link to comment
Share on other sites

Hey everyone im having a little trouble with my forum pagination on the replies. I am using the the id of the topic as the page so this is what it looks like for the link:

" echo "  <tr><td height='50' align='center' valign='top' bgcolor='#AAAAAA'><b>$username</b><br />$date<br />$time</td>

  <td height='50' align='center' bgcolor='#AAAAAA'><b><a href='viewtopic.php?id=$id'>$topic</a></b></td></tr>";"

so the link is http://...........viewtopic.php?id=1

I am using this pagination

  <?

//display data

$get = mysql_query("SELECT * FROM reply WHERE reply_id='$id' LIMIT $start, $per_page");

while ($row = mysql_fetch_assoc($get))

  {

//get data

$a_username = $row['a_username'];

$a_date = $row['a_date'];

$a_time = $row['a_time'];

$a_reply = $row['a_reply'];

 

echo "  <tr><td height='50' align='center' valign='top' bgcolor='#AAAAAA'><b>$a_username</b><br />$a_date<br />$a_time</td>

  <td height='50' align='center' bgcolor='#AAAAAA'>$a_reply</td></tr>";

 

  }

 

  ?>

 

  </table>

  <p />

 

  <div align='center'>

  <?

//setup prev and next variables

$prev = $start - $per_page;

$next = $start + $per_page;

 

//show prev button

if (!($start<=0))

echo "<a href='viewtopic.php?start=$prev'>Prev</a> ";

 

//show page numbers

 

//set variable for first page

$i=1;

 

for ($x=0;$x<$record_count;$x=$x+$per_page)

{

if ($start!=$x)

echo "<a href='viewtopic.php?start=$x'>$i</a> ";

else

echo "<a href='viewtopic.php?start=$x'><b>$i</b></a> ";

$i++;

}

 

//show next button

if (!($start>=$record_count - $per_page))

echo " <a href='viewtopic.php?start=$next'>Next</a>";

 

?>

 

but then when I click on the next page or one of those links it comes out like this http://...........viewtopic.php?id=1?start=2

then click it again http://...........viewtopic.php?id=1?start=2?start=2 and adds that every time I click it

can anyone help its the last part of making my forum, please?

I think your coding concept is not quite right seeing from the output, you are trying to add pages into the page number instead of displaying them on page. I have a pagination example, you might consider:

//Set number of entries on each page:
//max entries per page
		$limit = 3;
		//Query the database to get total entries:
		$news = file("admin/news.txt");
		$totalrows = count($news);
		//Special Cases:
		$pagination = true;
		if ($totalrows == 0) {$pagination = false;
		echo "<p align=center><br /><br />$db_noentries</p>";}
		elseif ($news == false) {$pagination = false;
		echo "<p align=center><br /><br />$db_error</p>";}

		if ($pagination == true) {
		//Page variable set:
		if (isset($_GET['page'])) {$page = $_GET['page'];}
		else {$page = 1;}

		//Organize result details:
		$lines = file("admin/news.txt");
		$lines = array_reverse($lines);

//Set variables:
		$startvalue = ($page * $limit) - $limit;
		$numofpages = $totalrows / $limit;
		$totalpages = ceil($numofpages);
		if ($page == $totalpages) {$endvalue = $totalrows;}
		else {$endvalue = $startvalue + $limit;}

		//Start looping through the entries:
		while ($startvalue < $endvalue){

		//Get general data:
		$data = explode(";seDp#", $lines[$startvalue]);
		//Perform organization:
		if (strlen($data[3]) > 500) {$extension = "...";}
		$entrycontent = "". substr($data[3], 0, 500) ."$extension";
		$extension = "";
		$textrcondition = 0;
		include("textreplacer.php");
		//Get Replies:
		$replies = file("newscomments/comments[{$data[2]}].txt");
		$total = count($replies);
		if (!file_exists("newscomments/comments[{$data[2]}].txt")){$total = 0;}

		echo "<a name=\"{$data[0]}\"></a>
		<h3>{$data[0]}</h3>
		<p>$entrycontent</p>
		<p class=\"post-footer align-right\">
		<a href=\"news.php?news={$data[2]}\" class=\"readmore\">Read more</a>
		<a href=\"news.php?news={$data[2]}#comments\" class=\"comments\">Comments ($total)</a>
		<span class=\"date\">{$data[1]}</span>
		</p>" . "\r\n";
		$startvalue ++;}
		//Starts page links:
		echo "<p align=center>";
		//Sets link for first page:
		if ($page != 1) {$pageprev = $page - 1;
		echo "<a href=\"{$_SERVER['PHP_SELF']}?page=1\"><<</a>  ";
		echo "<a href=\"{$_SERVER['PHP_SELF']}?page=$pageprev\">PREV </a> ";}
		else {echo "PREV ";}
		//Page Range sorting:
		if ($page <= 5) {$pagelowerlim = 1;} else {
		if ($totalpages <= 11) {$pagelowerlim = 1;}
		else {if (($totalpages - $page) < 5) {$pagelowerlim = $totalpages - 10;}
		else {$pagelowerlim = $page - 5;}}}
		if ($page <= 5) {
		if ($totalpages <= 11) {$pageupperlim = $totalpages;} else {$pageupperlim = 11;}}
		else {if (($totalpages - $page) >= 5) {$pageupperlim = $page + 5;} else {$pageupperlim = $totalpages;}}
		//Looping through page numbers:
		$i = $pagelowerlim;
		while ($i <= $pageupperlim) {
		if ($i == $page) {echo "[$i] ";}
		else {echo "<a href=\"{$_SERVER['PHP_SELF']}?page=$i\">$i</a> ";}
		$i ++;}
		//Set link for last page:
		if ($page != $totalpages) {$pagenext = $page + 1;
		echo "<a href=\"{$_SERVER['PHP_SELF']}?page=$pagenext\">NEXT </a> ";
		echo "<a href=\"{$_SERVER['PHP_SELF']}?page=$totalpages\">>></a>";}
		else {echo "NEXT ";}
		echo "</p>";}

This gives PREV [1] 2 3 NEXT  >>...etc you can click on, I modified it a bit so it only outputs 11 pages on the page if number of pages exceed 11.

Ted

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.