ngreenwood6 Posted December 12, 2008 Share Posted December 12, 2008 Can you post your code how it looks now so that we can take a look at what it currently is doing? Link to comment https://forums.phpfreaks.com/topic/136651-still-have-a-pagination-problem/page/2/#findComment-714034 Share on other sites More sharing options...
Noskiw Posted December 12, 2008 Author Share Posted December 12, 2008 <?php $id = $_GET['id']; $page = (!$_GET['page'] || $_GET['page'] < 0) ? "1" : $_GET['page']; $page = ceil($page); $limit = 10; $start = $limit; $end = $page*$limit-($limit); if(isset($id)){ $sql = "SELECT * FROM forum_topics WHERE id='".$id."'"; $res = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($res) == 0){ echo "This topic does not exist!\n"; }else{ $row = mysql_fetch_assoc($res); $sql2 = "SELECT admin FROM forum_sub_cats WHERE id='".$row['cid']."'"; $res2 = mysql_query($sql2) or die(mysql_error()); $row2 = mysql_fetch_assoc($res2); if($row2['admin'] == 1 && $admin_user_level == 0){ echo "You cannot view this topic because you are not an admin!\n"; }else{ $a = (isa($row['uid'])) ? "<font style=\"color:#800000;\">ADMIN</font>" : ""; $amount_check = "SELECT * FROM forum_replies WHERE tid='".$tid."'"; $amount_check_res = mysql_query($amount_check) or die(mysql_error()); $amount_count = mysql_num_rows($amount_check_res); $pages = ceil($amount_count/$limit); $previous = ($page-1 <= 0) ? "« Prev" : "<a href=\"./forum-index.php?act=topic&id=".$id."&page=".($page-1)."\">« Prev</a>"; $nextpage = ($page+1 <= $pages) ? " Next »" : " <a href=\"./forum-index.php?act=topic&id=".$id."&page=".($page+1)."\">Next »</a>"; echo "<tr><td align=\"right\" colspan=\"2\">\n"; echo "Pages: "; echo $previous; for($i=1;$i<=$pages;$i++){ $href = ($page == $i) ? " ".$i." " : " <a href=\"./forum-index.php?act=create&id=".$id."&page=".$i."\">".$i."</a> "; echo $href; } echo $nextpage; echo "</td></tr>\n"; echo "<table border=\"0\" width=\"100%\" cellspacing=\"3\" cellpadding=\"3\">\n"; echo "<tr><td colspan=\"2\" align=\"left\" class=\"forum_header\"><b><font size=\"3\">".$row['title']."</font></b><font size=\"3\"> - Posted On: <em>".$row['date']."</em></font></td></tr>\n"; echo "<tr><td align=\"left\" width=\"15%\" valign=\"top\" class=\"forum_header\">".uid($row['uid'], true)."<br>Posts: 0<br>".$a."</td>"; echo "<td align=\"left\" valign=\"top\" class=\"forum_header\">"; echo topic($row['message']); echo "</td>\n"; echo "</tr>\n"; $select_sql = "SELECT * FROM `forum_replies`WHERE tid = ".$id." ORDER BY id ASC LIMIT ".$end.", ".$start.""; $select_res = mysql_query($select_sql) or die(mysql_error()); while($rowr = mysql_fetch_assoc($select_res)){ echo "<tr><td colspan=\"2\" align=\"left\" class=\"forum_header\"><font size=\"3\"> - Posted On: <em>".$rowr['date']."</em></font></td></tr>\n"; echo "<tr><td align=\"left\" width=\"15%\" valign=\"top\" class=\"forum_header\">".uid($rowr['uid'], true)."<br>Posts: 0<br>".$a."</td>"; echo "<td align=\"left\" valign=\"top\" class=\"forum_header\">"; echo topic($rowr['message']); echo "</td>\n"; echo "</tr>\n"; } echo "<form method=\"post\" action=\"./forum-index.php?act=reply&id=".$row['id']."\">\n"; echo "<tr><td colspan=\"2\" align=\"center\"><textarea style=\"width:90%\" name=\"reply\"></textarea><br><input type=\"submit\" name=\"submit\" value=\"add reply!\" style=\"width:90%\" /></td></tr>\n"; echo "</table>\n"; } } }else{ echo "Please view a valid topic!\n"; } ?> Link to comment https://forums.phpfreaks.com/topic/136651-still-have-a-pagination-problem/page/2/#findComment-714050 Share on other sites More sharing options...
Brian W Posted December 12, 2008 Share Posted December 12, 2008 about pages, I personally have exhausted my ideas on that. maybe ngreenwood6 will help on that one more than I can. as for the HTML entities, what does topic() do? The problem is in there. Post the code for that function and I can help you on that. Link to comment https://forums.phpfreaks.com/topic/136651-still-have-a-pagination-problem/page/2/#findComment-714058 Share on other sites More sharing options...
ngreenwood6 Posted December 12, 2008 Share Posted December 12, 2008 what happens if you echo out $pages. Link to comment https://forums.phpfreaks.com/topic/136651-still-have-a-pagination-problem/page/2/#findComment-714069 Share on other sites More sharing options...
Noskiw Posted December 12, 2008 Author Share Posted December 12, 2008 function topic($input){ //bbcode return strip_tags(stripslashes(htmlentities(htmlspecialchars($input)))); } Link to comment https://forums.phpfreaks.com/topic/136651-still-have-a-pagination-problem/page/2/#findComment-714074 Share on other sites More sharing options...
ngreenwood6 Posted December 12, 2008 Share Posted December 12, 2008 It seems to me like the pages is not getting calculated right. did you try to echo out the $pages variable somewhere and figure out what the value is? Link to comment https://forums.phpfreaks.com/topic/136651-still-have-a-pagination-problem/page/2/#findComment-714082 Share on other sites More sharing options...
Noskiw Posted December 12, 2008 Author Share Posted December 12, 2008 no but i don't know where to echo it out. Link to comment https://forums.phpfreaks.com/topic/136651-still-have-a-pagination-problem/page/2/#findComment-714087 Share on other sites More sharing options...
ngreenwood6 Posted December 12, 2008 Share Posted December 12, 2008 find this line: echo $nextpage; put this right below that line: echo $pages; This is good for troubleshooting to see if your variables are getting the right values. Link to comment https://forums.phpfreaks.com/topic/136651-still-have-a-pagination-problem/page/2/#findComment-714088 Share on other sites More sharing options...
Brian W Posted December 12, 2008 Share Posted December 12, 2008 function topic($input){ //bbcode return strip_tags(stripslashes(htmlentities(htmlspecialchars($input)))); } get rid of htmlentities or htmlspecialchars, they both need be. Link to comment https://forums.phpfreaks.com/topic/136651-still-have-a-pagination-problem/page/2/#findComment-714104 Share on other sites More sharing options...
Noskiw Posted December 12, 2008 Author Share Posted December 12, 2008 it displays entities now, thankyou. Link to comment https://forums.phpfreaks.com/topic/136651-still-have-a-pagination-problem/page/2/#findComment-714108 Share on other sites More sharing options...
ngreenwood6 Posted December 12, 2008 Share Posted December 12, 2008 oh yeah I forgot to tell you that if you did that it would echo the value next to where the word next is. Link to comment https://forums.phpfreaks.com/topic/136651-still-have-a-pagination-problem/page/2/#findComment-714112 Share on other sites More sharing options...
Noskiw Posted December 12, 2008 Author Share Posted December 12, 2008 oh yeah I forgot to tell you that if you did that it would echo the value next to where the word next is. BTW, i tried, it says, page=2 pages=0; Link to comment https://forums.phpfreaks.com/topic/136651-still-have-a-pagination-problem/page/2/#findComment-714117 Share on other sites More sharing options...
ngreenwood6 Posted December 12, 2008 Share Posted December 12, 2008 try changing the value of $pages from: $pages = ceil($amount_count/$limit); to: $pages = 2; I just want to see if it limits it. Link to comment https://forums.phpfreaks.com/topic/136651-still-have-a-pagination-problem/page/2/#findComment-714124 Share on other sites More sharing options...
Noskiw Posted December 12, 2008 Author Share Posted December 12, 2008 no it doesn't limit it, but you made the numbers show up, but the 2nd page link doesn't show up go to http://nostrich.freetzi.com/forum-index.php?act=topic&id=21 Link to comment https://forums.phpfreaks.com/topic/136651-still-have-a-pagination-problem/page/2/#findComment-714129 Share on other sites More sharing options...
ngreenwood6 Posted December 12, 2008 Share Posted December 12, 2008 I see the problem now. Give me a minute to figure out how to fix it. Link to comment https://forums.phpfreaks.com/topic/136651-still-have-a-pagination-problem/page/2/#findComment-714132 Share on other sites More sharing options...
Noskiw Posted December 12, 2008 Author Share Posted December 12, 2008 thx. Link to comment https://forums.phpfreaks.com/topic/136651-still-have-a-pagination-problem/page/2/#findComment-714135 Share on other sites More sharing options...
ngreenwood6 Posted December 12, 2008 Share Posted December 12, 2008 try changing this: for($i=1;$i<=$pages;$i++){ $href = ($page == $i) ? " ".$i." " : " <a href=\"./forum-index.php?act=create&id=".$id."&page=".$i."\">".$i."</a> "; echo $href; } to this: for($i=1;$i<$pages;$i++){ $href = ($page == $i) ? " ".$i." " : " <a href=\"./forum-index.php?act=create&id=".$id."&page=".$i."\">".$i."</a> "; echo $href; } that should fix the page numbering issue. Link to comment https://forums.phpfreaks.com/topic/136651-still-have-a-pagination-problem/page/2/#findComment-714137 Share on other sites More sharing options...
Noskiw Posted December 12, 2008 Author Share Posted December 12, 2008 comes up with the first number, but not the rest, i have 3 pages now. Link to comment https://forums.phpfreaks.com/topic/136651-still-have-a-pagination-problem/page/2/#findComment-714142 Share on other sites More sharing options...
ngreenwood6 Posted December 12, 2008 Share Posted December 12, 2008 actually sorry that was wrong i was looking at it backwards. if you have 3 pages you can change the $pages = 3 Link to comment https://forums.phpfreaks.com/topic/136651-still-have-a-pagination-problem/page/2/#findComment-714145 Share on other sites More sharing options...
Brian W Posted December 12, 2008 Share Posted December 12, 2008 $i = 0? for($i=0;$i<=$pages;$i++){ it runs the $i++ before output I think. Link to comment https://forums.phpfreaks.com/topic/136651-still-have-a-pagination-problem/page/2/#findComment-714146 Share on other sites More sharing options...
ngreenwood6 Posted December 12, 2008 Share Posted December 12, 2008 Try changing this: $nextpage = ($page+1 <= $pages) ? " Next »" : " <a href=\"./forum-index.php?act=topic&id=".$id."&page=".($page+1)."\">Next »</a>"; to this: $nextpage = ($page+1 >= $pages) ? " Next »" : " <a href=\"./forum-index.php?act=topic&id=".$id."&page=".($page+1)."\">Next »</a>"; I think that should stop the page from going on and on. and Brian W it doesnt run that until after the first time around. Link to comment https://forums.phpfreaks.com/topic/136651-still-have-a-pagination-problem/page/2/#findComment-714155 Share on other sites More sharing options...
ngreenwood6 Posted December 12, 2008 Share Posted December 12, 2008 also if you change this: $previous = ($page-1 <= 0) ? "« Prev" : "<a href=\"./forum-index.php?act=topic&id=".$id."&page=".($page-1)."\">« Prev</a>"; to this: $previous = ($page-1 <= 1) ? "« Prev" : "<a href=\"./forum-index.php?act=topic&id=".$id."&page=".($page-1)."\">« Prev</a>"; it should then display the prev not as a link when you first go there on the first page. Link to comment https://forums.phpfreaks.com/topic/136651-still-have-a-pagination-problem/page/2/#findComment-714159 Share on other sites More sharing options...
Brian W Posted December 12, 2008 Share Posted December 12, 2008 it doesnt run that until after the first time around. fair enough... but why doesn't it work than? btw, I watched the numbers work than it went back to only showing zero. what happened? Link to comment https://forums.phpfreaks.com/topic/136651-still-have-a-pagination-problem/page/2/#findComment-714165 Share on other sites More sharing options...
ngreenwood6 Posted December 12, 2008 Share Posted December 12, 2008 you need to change this: for($i=0;$i<=$pages;$i++){ $href = ($page == $i) ? " ".$i." " : " <a href=\"./forum-index.php?act=create&id=".$id."&page=".$i."\">".$i."</a> "; echo $href; } back to this: for($i=1;$i<=$pages;$i++){ $href = ($page == $i) ? " ".$i." " : " <a href=\"./forum-index.php?act=create&id=".$id."&page=".$i."\">".$i."</a> "; echo $href; } so that you wont see a zero page. Link to comment https://forums.phpfreaks.com/topic/136651-still-have-a-pagination-problem/page/2/#findComment-714169 Share on other sites More sharing options...
ngreenwood6 Posted December 12, 2008 Share Posted December 12, 2008 can you repost code so that we can look at it now. Link to comment https://forums.phpfreaks.com/topic/136651-still-have-a-pagination-problem/page/2/#findComment-714174 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.