Zoofu Posted August 21, 2009 Share Posted August 21, 2009 <?php $id = mss($_GET['id']); $page = (!$_GET['page'] || $_GET['page'] < 0) ? "1" : $_GET['page']; $page = ceil($page); $limit = 10; $start = $limit; $end = $page*$limit-($limit); if($id){ $sql = "SELECT * FROM `forum_subcats` WHERE `id`='".$id."'"; $res = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($res) == 0){ echo "The forum category does not exist!\n"; }else { $row = mysql_fetch_assoc($res); if($row['admin'] == 1 &&$admin_user_level == '0'){ echo "You do not have permission to view this forum.\n"; }else { $amount_check = "SELECT * FROM `forum_topics` WHERE `cid`='".$id."'"; $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=\"./index.php?act=forum&id=".$id."&page=".($page-1)."\">« Prev</a>"; $nextpage = ($page+1 > $pages) ? "Next »" : "<a href=\"./index.php?act=forum&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=\"./index.php?act=forum&id=".$id."&page=".$i."\">".$i."</a> "; echo $href; } echo $nextpage; echo "</td></tr>\n"; $sql2 = "SELECT * FROM `forum_topics` WHERE `cid`='".$row['id']."' ORDER BY time DESC"; $res2 = mysql_query($sql2) or die(mysql_error()); if(mysql_num_rows($res2) == 0){ echo "There are no topics in this forum, <a href=\"./index.php?act=create&id=".$row['id']."\">Click Here</a> to create a topic!\n"; }else { echo "<table border=\"0\" cellspacing=\"3\" cellpadding=\"3\" width=\"100%\">\n"; echo "<tr><td colspan=\"4\" align=\"right\"><a href=\"./index.php?act=create&id=".$row['id']."\">Create Topic</a></td></tr>\n"; echo "<tr align=\"center\"><td class=\"forum_header\">Topic</td><td class=\"forum_header\">Creator</td><td class=\"forum_header\">Replies</td></tr>\n"; while($row2 = mysql_fetch_assoc($res2)){ $sql3 = "SELECT count(*) AS num_replies FROM `forum_replies` WHERE `tid`='".$row2['id']."'"; $res3 = mysql_query($sql3) or die(mysql_error()); $row3 = mysql_fetch_assoc($res3); echo "<tr align=\"center\"\"><td><a href=\"./index.php?act=topic&id=".$row2['id']."\">".s($row2['title'])."</a></td><td>".uid($row2['uid'])."</td><td>".$row3['num_replies']."</td></tr>\n"; } echo "</table></table>\n"; } } } }else { echo "Please supply a category ID!\n"; } ?> Okay, when it gets over the limit, it makes other pages, and when you click it, it goes to the page.. But the topics don't go onto the other page, they are ALL displayed on all pages. They don't end at 10 and stick the rest on the next. Link to comment https://forums.phpfreaks.com/topic/171241-pagination-not-working-fully/ Share on other sites More sharing options...
Zoofu Posted August 21, 2009 Author Share Posted August 21, 2009 Also, if anyone could: Why isn't this working in my stylesheet? ... body { background-color:#EEE; color:#000; font-family:Tahoma; font-size:10pt; } Link to comment https://forums.phpfreaks.com/topic/171241-pagination-not-working-fully/#findComment-903027 Share on other sites More sharing options...
kratsg Posted August 21, 2009 Share Posted August 21, 2009 As I can tell, you have no "LIMIT #,#" in your query. Let me give you my idea of a basic pagination script (and I use this quite often) since it's very simple and easy to follow: <?php if(!isset($_GET['ppage']) || !is_numeric($_GET['ppage'])){ $ppage = 1; } else { $ppage = $_GET['ppage']; } // Define the number of results per page $max_results = 10; // Figure out the total number of results in DB: $query = "SELECT * FROM `table` WHERE `column` = 'value'";//build your initial query to fetch ALL data $total_results = mysql_num_rows(mysql_query($query)); // Figure out the total number of pages. Always round up using ceil() $total_pages = ceil($total_results / $max_results); if($ppage > $total_pages){$ppage = $total_pages;}//cut off if their ppage > total pages // Figure out the limit for the query based // on the current page number. $from = (($ppage * $max_results) - $max_results); // Perform MySQL query on only the current page number's results $sql = mysql_query($query." LIMIT $from, $max_results"); if(mysql_num_rows($sql) == 0){ //show error here saying there are no results } while($row = mysql_fetch_array($sql)){ // Build your formatted results here. } // Build Page Number Hyperlinks echo "<center>Select a Page<br />"; // Build Previous Link if($ppage > 1){ $prev = ($ppage - 1); echo "<a href=\"".$_SERVER['PHP_SELF']."?ppage=$prev\"><<Previous</a> "; } for($i = 1; $i <= $total_pages; $i++){ if(($ppage) == $i){ echo "<font color='red' size='4'><b>$i </b></font>"; } else { echo "<a href=\"".$_SERVER['PHP_SELF']."?ppage=$i\">$i</a> "; } } // Build Next Link if($ppage < $total_pages){ $next = ($ppage + 1); echo "<a href=\"".$_SERVER['PHP_SELF']."?ppage=$next\">Next>></a>"; } echo "</center>"; ?> Also, if anyone could: Why isn't this working in my stylesheet? ... body { background-color:#EEE; color:#000; font-family:Tahoma; font-size:10pt; } It seems to work, perhaps if you have Firebug (FireFox add on) and you inspect your body element and view the styles applied, you should see overlapping styles. Let's say I have: <body> <span style="color:red;">Some text</span> </body> with your defined styles for the body, that text will show red as inline styles override all other styles. Link to comment https://forums.phpfreaks.com/topic/171241-pagination-not-working-fully/#findComment-903048 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.