我有数据库的结构是这样的:如何在PHP和MySQL中的一页中显示用户的帖子?
table name: tblpost
,我要显示所有岗位由用户像展后通过只在页面名称的多个用户:allpost.php
我想得到如下结果:
那么如何显示这样的数据呢?非常感谢您的答复。
我有数据库的结构是这样的:如何在PHP和MySQL中的一页中显示用户的帖子?
table name: tblpost
,我要显示所有岗位由用户像展后通过只在页面名称的多个用户:allpost.php
我想得到如下结果:
那么如何显示这样的数据呢?非常感谢您的答复。
假设您使用PDO。
$stmt = $db->prepare("SELECT * from tblposts where post_by=:post_by");
$stmt->bindParam(':post_by',$user);
$stmt->execute();
//Fetches the posts for the certain user you want
$posts = $stmt->fetch(PDO::FETCH_ASSOC);
的MySQLi:
$stmt = $mysqli->prepare("SELECT * from tblposts where post_by=?");
$stmt->bind_param('s',$user);
$stmt->execute();
$res = $stmt->get_result();
while ($row = mysqli_fetch_assoc($res)) {
echo $row['post_date'];
}
你可以给我MySQLi程序代码,因为我不明白PDO代码吗? –
@MiechChamnan编辑我的评论。添加mysqli –
,能不能请您编辑表示你尝试的问题? – alepuzio