Jump to content

Paging and a name


newbtophp

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.