我的数据库:
这是我用于检索帖子的php代码:示例post.php?id=12
:
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
include_once('../connection.php');
include_once('../comments.php');
include_once('../gallery.php');
class Objects{
//fetch all posts
public function get_information(){
global $pdo;
$query = $pdo->prepare('SELECT * FROM `post` LEFT JOIN post_gallery ON post.post_id = post_gallery.user WHERE post_cat = "Cars"');
$query->execute();
return $query->fetchAll(PDO::FETCH_ASSOC);
}
//fetch post data by post id
public function fetch_data($pid){
global $pdo;
$query = $pdo->prepare('SELECT * FROM `post` LEFT JOIN post_gallery ON post.post_id = post_gallery.user WHERE post_cat = "Cars"');
$query->BindValue(1,$pid);
$query->execute();
return $query->fetch();
}
}
?>
此代码用于检索posts
和post_gallery
信息和图像。问题是,当用户单击随机帖子并转到该页面上的post.php?id=12
时,将显示由post_cat = "Cars"
而非?id=12
定义的所有帖子。有人知道我错在哪里吗?