simmsy Posted April 9, 2011 Share Posted April 9, 2011 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 https://forums.phpfreaks.com/topic/233217-pagination-trouble/ Share on other sites More sharing options...
ted_chou12 Posted April 9, 2011 Share Posted April 9, 2011 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 https://forums.phpfreaks.com/topic/233217-pagination-trouble/#findComment-1199470 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.