Brian W Posted December 12, 2008 Share Posted December 12, 2008 now the numbers work but the next link doesn't work after the first page. Link to comment https://forums.phpfreaks.com/topic/136651-still-have-a-pagination-problem/page/3/#findComment-714178 Share on other sites More sharing options...
Noskiw Posted December 12, 2008 Author Share Posted December 12, 2008 actually, those two things made it worse. i have changed the $nextpage to $nextpage = ($page+1 >= $pages) ? " Next »" : " <a href=\"./forum-index.php?act=topic&id=".$id."&page=".($page+1)."\">Next »</a>"; but the next link only shows up on the first page. and not the second. anything wrong there? Link to comment https://forums.phpfreaks.com/topic/136651-still-have-a-pagination-problem/page/3/#findComment-714184 Share on other sites More sharing options...
Brian W Posted December 12, 2008 Share Posted December 12, 2008 the >= maybe just > try it (if my trouble shooting sucks, its cuz my trouble shooting sucks lol) Link to comment https://forums.phpfreaks.com/topic/136651-still-have-a-pagination-problem/page/3/#findComment-714187 Share on other sites More sharing options...
Noskiw Posted December 12, 2008 Author Share Posted December 12, 2008 dude, that worked. Link to comment https://forums.phpfreaks.com/topic/136651-still-have-a-pagination-problem/page/3/#findComment-714191 Share on other sites More sharing options...
Brian W Posted December 12, 2008 Share Posted December 12, 2008 partially... the last post is not shown on page 3. I replied and it is on page 4 but the pages only shows up to 3 still. math problem Link to comment https://forums.phpfreaks.com/topic/136651-still-have-a-pagination-problem/page/3/#findComment-714200 Share on other sites More sharing options...
Brian W Posted December 12, 2008 Share Posted December 12, 2008 $pages = ceil($amount_count/$limit); 31/10 = 3.1 round up and makes 4... so problem isn't there i think. (to be sure, echo $amount_count somewhere and be sure it is 31 (or more if someone else posts)) but I don't see where is is otherwise. Link to comment https://forums.phpfreaks.com/topic/136651-still-have-a-pagination-problem/page/3/#findComment-714207 Share on other sites More sharing options...
Noskiw Posted December 12, 2008 Author Share Posted December 12, 2008 i echod amount_count but it said 0. Link to comment https://forums.phpfreaks.com/topic/136651-still-have-a-pagination-problem/page/3/#findComment-714215 Share on other sites More sharing options...
Brian W Posted December 12, 2008 Share Posted December 12, 2008 umm, that isn't good. and, why is your numbers and next link broken again. put this right before you loop of replies. echo "amount count = ".$amount_count; Link to comment https://forums.phpfreaks.com/topic/136651-still-have-a-pagination-problem/page/3/#findComment-714217 Share on other sites More sharing options...
Noskiw Posted December 13, 2008 Author Share Posted December 13, 2008 bump, still says zero. can't get it to work. Link to comment https://forums.phpfreaks.com/topic/136651-still-have-a-pagination-problem/page/3/#findComment-714458 Share on other sites More sharing options...
Noskiw Posted December 13, 2008 Author Share Posted December 13, 2008 bump, still says zero. can't get it to work. still says zero! Link to comment https://forums.phpfreaks.com/topic/136651-still-have-a-pagination-problem/page/3/#findComment-714482 Share on other sites More sharing options...
Noskiw Posted December 13, 2008 Author Share Posted December 13, 2008 this is the code now <?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 = 4; $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 $previous; for($i=1;$i<=$pages;$i++){ $href = ($page == $i) ? " ".$i." " : " <a href=\"./forum-index.php?act=topic&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: ".posts($row['uid'])."<br>".$a."</td>\n"; 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: ".posts($rowr['uid'])."<br>".$a."</td>\n"; 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"; } ?> i dont know how to fix it. in the $pages bit Link to comment https://forums.phpfreaks.com/topic/136651-still-have-a-pagination-problem/page/3/#findComment-714679 Share on other sites More sharing options...
Noskiw Posted December 14, 2008 Author Share Posted December 14, 2008 this is the code now <?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 = 4; $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 $previous; for($i=1;$i<=$pages;$i++){ $href = ($page == $i) ? " ".$i." " : " <a href=\"./forum-index.php?act=topic&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: ".posts($row['uid'])."<br>".$a."</td>\n"; 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: ".posts($rowr['uid'])."<br>".$a."</td>\n"; 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"; } ?> i dont know how to fix it. in the $pages bit anyone? Link to comment https://forums.phpfreaks.com/topic/136651-still-have-a-pagination-problem/page/3/#findComment-715054 Share on other sites More sharing options...
Noskiw Posted December 14, 2008 Author Share Posted December 14, 2008 ive been waiting 2 days for a reply! Link to comment https://forums.phpfreaks.com/topic/136651-still-have-a-pagination-problem/page/3/#findComment-715090 Share on other sites More sharing options...
Yesideez Posted December 14, 2008 Share Posted December 14, 2008 Add this line echo 'id='.$id.', page='.$page.', start='.$start.', end='.$end; Immediately before this line if(isset($id)){ I already see what the problem is - just want to get some extra information. Link to comment https://forums.phpfreaks.com/topic/136651-still-have-a-pagination-problem/page/3/#findComment-715102 Share on other sites More sharing options...
Yesideez Posted December 14, 2008 Share Posted December 14, 2008 OK try this code - it looks like you were trying to calculate how many pages before running a query to find out how many lines were being returned. I've re-written the first chunk but formatted everything else - back up your original script first before trying this one. <?php $intMax=10; //NUMBER OF ITEMS PER PAGE $id = intval($_GET['id']); $page = ($_GET['page'] > 0 ? "1" : intval($_GET['page']); //$page = ceil($page); //$limit = 10; //$start = $limit; //$end = $page*$limit-($limit); if ($id>0) { $sql="SELECT * FROM forum_topics WHERE id='".$id."'"; $intTotalMatched=mysql_num_rows(mysql_query($sql)); if (mysql_num_rows($res) == 0) { echo "This topic does not exist - Please view a valid topic!\n"; } else { $intTotalPages=ceil($intTotalMatched/$intMax); $intStart=(($intPage*$intMax)-$intMax); if ($page>$intTotalPages) {$page=$intTotalPages;} echo 'id='.$id.', page='.$page.', totalmatched='.$intTotalMatched.', totalpages='.$intTotalPages.', start='.$intStart.', end='.$intMax.'<br />'; $res=mysql_query($sql." LIMIT ".$intStart.",".$intMax); echo 'sql='.$sql.'<br />'; // $sql = "SELECT * FROM forum_topics WHERE id='".$id."'"; // $res = mysql_query($sql) or die(mysql_error()); $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 = 4; $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 $previous; for($i=1;$i<=$pages;$i++){ $href = ($page == $i) ? " ".$i." " : " <a href=\"./forum-index.php?act=topic&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: ".posts($row['uid'])."<br>".$a."</td>\n"; 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: ".posts($rowr['uid'])."<br>".$a."</td>\n"; 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"; } } } ?> Link to comment https://forums.phpfreaks.com/topic/136651-still-have-a-pagination-problem/page/3/#findComment-715109 Share on other sites More sharing options...
Yesideez Posted December 14, 2008 Share Posted December 14, 2008 It's also going to dump a load of debug variables to your browser as well. Link to comment https://forums.phpfreaks.com/topic/136651-still-have-a-pagination-problem/page/3/#findComment-715110 Share on other sites More sharing options...
Noskiw Posted December 14, 2008 Author Share Posted December 14, 2008 OK try this code - it looks like you were trying to calculate how many pages before running a query to find out how many lines were being returned. I've re-written the first chunk but formatted everything else - back up your original script first before trying this one. <?php $intMax=10; //NUMBER OF ITEMS PER PAGE $id = intval($_GET['id']); $page = ($_GET['page'] > 0 ? "1" : intval($_GET['page']); //$page = ceil($page); //$limit = 10; //$start = $limit; //$end = $page*$limit-($limit); if ($id>0) { $sql="SELECT * FROM forum_topics WHERE id='".$id."'"; $intTotalMatched=mysql_num_rows(mysql_query($sql)); if (mysql_num_rows($res) == 0) { echo "This topic does not exist - Please view a valid topic!\n"; } else { $intTotalPages=ceil($intTotalMatched/$intMax); $intStart=(($intPage*$intMax)-$intMax); if ($page>$intTotalPages) {$page=$intTotalPages;} echo 'id='.$id.', page='.$page.', totalmatched='.$intTotalMatched.', totalpages='.$intTotalPages.', start='.$intStart.', end='.$intMax.'<br />'; $res=mysql_query($sql." LIMIT ".$intStart.",".$intMax); echo 'sql='.$sql.'<br />'; // $sql = "SELECT * FROM forum_topics WHERE id='".$id."'"; // $res = mysql_query($sql) or die(mysql_error()); $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 = 4; $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 $previous; for($i=1;$i<=$pages;$i++){ $href = ($page == $i) ? " ".$i." " : " <a href=\"./forum-index.php?act=topic&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: ".posts($row['uid'])."<br>".$a."</td>\n"; 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: ".posts($rowr['uid'])."<br>".$a."</td>\n"; 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"; } } } ?> the new code hasn't worked. Link to comment https://forums.phpfreaks.com/topic/136651-still-have-a-pagination-problem/page/3/#findComment-715111 Share on other sites More sharing options...
Yesideez Posted December 14, 2008 Share Posted December 14, 2008 Now if I'm going to help you I need a little more information that "it hasn't worked" What was the output? In what way didn't it work? Did it do anything different? Have you got this online somewhere so I can see for myself? Link to comment https://forums.phpfreaks.com/topic/136651-still-have-a-pagination-problem/page/3/#findComment-715112 Share on other sites More sharing options...
Noskiw Posted December 14, 2008 Author Share Posted December 14, 2008 Now if I'm going to help you I need a little more information that "it hasn't worked" What was the output? In what way didn't it work? Did it do anything different? Have you got this online somewhere so I can see for myself? yes this is online 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/3/#findComment-715118 Share on other sites More sharing options...
Yesideez Posted December 14, 2008 Share Posted December 14, 2008 Sorry, I get a "Page Load Error" in Firefox. Link to comment https://forums.phpfreaks.com/topic/136651-still-have-a-pagination-problem/page/3/#findComment-715122 Share on other sites More sharing options...
Noskiw Posted December 14, 2008 Author Share Posted December 14, 2008 same. don't know why though. ill try it in IE. doesn't work in IE either. Link to comment https://forums.phpfreaks.com/topic/136651-still-have-a-pagination-problem/page/3/#findComment-715123 Share on other sites More sharing options...
Yesideez Posted December 14, 2008 Share Posted December 14, 2008 You mean you can't access the web page either? Link to comment https://forums.phpfreaks.com/topic/136651-still-have-a-pagination-problem/page/3/#findComment-715127 Share on other sites More sharing options...
Noskiw Posted December 14, 2008 Author Share Posted December 14, 2008 You mean you can't access the web page either? nope, don't know why though. seemed to work before i got this other addon. its working again. Link to comment https://forums.phpfreaks.com/topic/136651-still-have-a-pagination-problem/page/3/#findComment-715129 Share on other sites More sharing options...
Yesideez Posted December 14, 2008 Share Posted December 14, 2008 It's asking me to register to view the page - does your register process work? Link to comment https://forums.phpfreaks.com/topic/136651-still-have-a-pagination-problem/page/3/#findComment-715131 Share on other sites More sharing options...
Noskiw Posted December 14, 2008 Author Share Posted December 14, 2008 yes it works, but i'm logged in and im getting the same page as you. grey background with 2 dividers. Link to comment https://forums.phpfreaks.com/topic/136651-still-have-a-pagination-problem/page/3/#findComment-715143 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.