When a user on my site visits their profile page, they are met with a list of posts they have made. I currently show 20 posts by default, but have no way of showing older posts. I would like to add a show more posts button that will load additional/older posts onto the page. What should i do to display more posts to the user after they click the show more button?
Here is my show posts function
function show_posts1($userid){
$posts = array();
$sql = "SELECT p.body, p.stamp, p.id,u.username, u.imagelocation
FROM posts p
INNER JOIN users u
ON p.user_id=u.id
WHERE p.user_id='$userid'
ORDER BY p.stamp DESC";
$result = mysql_query($sql);
while($data = mysql_fetch_object($result)){
$posts[] = array( 'stamp' => $data->stamp,
'userid' => $userid,
'body' => $data->body,
'username' => $data->username,
'imagelocation'=>$data->imagelocation,
'id'=>$data->id
);
}
return $posts;
}
Here is how i display the posts on the page
<?php
$posts = show_posts1($_SESSION['user_id']);
if (count($posts)){
?>
<table>
<?php
foreach ($posts as $key => $list){
echo "<tr>";
echo "<td>".$list['body']."
</td>";
echo "</tr>";
}
?>
</table>
<?php
}else{
?>
<p><b>You haven't posted anything yet!</b></p>
<?php
}
?>