Php 仅显示来自一个用户的帖子
您好,我的数据库中有一个名为posts的表: 1-id 2-poster 3-Title 4-date 5-hour 6-imagem 7-desc 然后我创建了一个帖子: id-1海报-Gary标题-机器学习的概念是什么? 日期-2021/05/19小时-下午4:32imagem -https://www.iberdrola.com/wcorp/gc/prod/pt_BR/comunicacion/machine_learning_mult_1_res/machine_learning_746x419.jpg desc-机器学习(英语中称为机器学习)是一种 自动构建分析模型的数据分析。信息技术 是人工智能的一个分支,基于系统 可以从数据中学习,识别模式并以最少的成本做出决策 人为干预 然后我创建了一个名为Index.html的php文件,该文件在Pdo中进行编码:Php 仅显示来自一个用户的帖子,php,database,pdo,Php,Database,Pdo,您好,我的数据库中有一个名为posts的表: 1-id 2-poster 3-Title 4-date 5-hour 6-imagem 7-desc 然后我创建了一个帖子: id-1海报-Gary标题-机器学习的概念是什么? 日期-2021/05/19小时-下午4:32imagem -https://www.iberdrola.com/wcorp/gc/prod/pt_BR/comunicacion/machine_learning_mult_1_res/machine_learning_746
<?php
include_once 'con.php';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<?php
$result_msg_cont = "SELECT * FROM posts ORDER BY id Desc";
$resultado_msg_cont = $conn->prepare($result_msg_cont);
$resultado_msg_cont->execute();
while ($row_msg_cont = $resultado_msg_cont->fetch(PDO::FETCH_ASSOC)) {
$post_id = $row_msg_cont['poster'];
$Post_Title = $row_msg_cont['Title'];
$data = $row_msg_cont['date'];
$hora = $row_msg_cont['hour'];
$desc = $row_msg_cont['desc'];
$imagem = $row_msg_cont['imagem'];
echo "<br><p> Posted in " . $data . " at " . $hora."</p><br>";
echo "<h2> $Post_Title</h2><br>";
echo "<img src='" .$imagem. "' class='img_posts'><br>";
echo " <br><h4 class='posts_desc'> " . $desc . "</h4><br>";
echo "poster: " . $post_id. "<br><br><hr>";
}
?>
</body>
</html>
简短答复:
您需要在查询中使用where子句
e、 g
长答覆:
在posts表中添加poster_unique_id列
再创建一个名为users的数据库表,其中包含id、unique\u id、name、user\u status和showhide等列。为每个海报细节的唯一id列使用唯一随机字符串
现在显示用户的名字(海报),并用GET value链接到他们
e、 g
**本例中未考虑数据清理等
我没有得到你的这一行-然后我创建了一个名为Index.html的php文件
是index.php还是index.html???您正在寻找WHERE
子句。这将允许您筛选查询。选择。。。其中'poster`='Gary'
$result_msg_cont = "SELECT * FROM posts where poster= 'Gary' ORDER BY id Desc";
<a href="index.php?poster=<?php echo $userdata['unique_id'];?>"> <?php echo $userdata['name']:?></a>
// HERE USER NAME AND UNIQUEID IS FETCHED FROM users TABLE
$poster = $_GET['poster'];
// then use query like
$result_msg_cont = "SELECT * FROM posts where poster_unique_id = '$poster' ORDER BY id Desc";