newbtophp Posted February 17, 2010 Share Posted February 17, 2010 Im alittle lost, Im trying to paginate a little basic php forum I created, so it displays 20 posts per page, and I've added a link to each post so i can scroll down to each post directly. However it doesn't seem to display 20 posts per page, and I can't seem to figure out a way to directly link them on other pages, because theirs no way to tell what page the post is on so I cant simply do topic.php?id=3#456 because I can't be certain post 456 will be on page 1. (if you understand what i mean?). :-\ <?php $topic_id = $_GET['id']; $start = @$_GET['start']; $limit = 15; if(!isset($start)) $start = 0; $sql = mysql_query("SELECT * FROM `site_posts` WHERE `post_topic` = '$topic_id' ORDER BY `post_id` ASC LIMIT $start , $limit"); while ($row = mysql_fetch_array($sql)){ $post_id = $row['post_id']; $post_author = stripslashes($row['post_author']); $post = stripslashes($row['post_body']); //display post - notice the link so i can access a post directly? : D echo $post_author." - <a name=\"{$post_id}\" href=\"#{$post_id}\">".$post."</a><br>"; $sql2 = mysql_query("SELECT * FROM `site_users` WHERE `user_username` = '$post_author'"); while ($row2 = mysql_fetch_array($sql2)){ $user_id = $row2['user_id']; } } $sql = mysql_query("SELECT `post_id` FROM `site_posts` WHERE `post_topic` = '$topic_id'"); $d=0; $f=0; $g=1; print "Page Select: "; while($order3=mysql_fetch_array($sql)) { if($f%$limit==0) { if ($start == $d) { print " $g |"; } else { print " <a href='{$_SERVER['PHP_SELF']}?start=$d&id=$topic_id'>$g</a> |"; } $g++; } $d=$d+1; $f++; } ?> Anyone can help me? :-\ Link to comment https://forums.phpfreaks.com/topic/192440-paging-and-a-name/ Share on other sites More sharing options...
LeadingWebDev Posted February 17, 2010 Share Posted February 17, 2010 $post=$_GET['post_num']; $page=$post/20; if(!is_int($page)) { $page=round($page, 1); $page=substr($page, 0, -2); } Link to comment https://forums.phpfreaks.com/topic/192440-paging-and-a-name/#findComment-1014001 Share on other sites More sharing options...
sader Posted February 17, 2010 Share Posted February 17, 2010 u could try to fix it with these fiew changes $topic_id = intval($_GET['id']); $limit = 15; $start = intval($_GET['start']) * $limit; //if(!isset($start))$start = 0; //rest code Link to comment https://forums.phpfreaks.com/topic/192440-paging-and-a-name/#findComment-1014003 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.