当我网站上的用户访问他们的个人资料页面时,他们会看到他们发布的帖子列表。我目前默认显示 20 个帖子,但无法显示较旧的帖子。我想添加一个显示更多帖子按钮,该按钮会将其他/较旧的帖子加载到页面上。在用户单击“显示更多”按钮后,我应该怎么做才能向用户显示更多帖子?
这是我的秀帖功能
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;
}
这是我在页面上显示帖子的方式
<?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
}
?>