Jump to content

Recommended Posts

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.