Php 左连接在一个页面中工作,但不在另一个页面中工作
我有这个代码目前在我的网站的另一个页面上运行良好Php 左连接在一个页面中工作,但不在另一个页面中工作,php,mysql,select,left-join,Php,Mysql,Select,Left Join,我有这个代码目前在我的网站的另一个页面上运行良好 $sql = "SELECT topics.topic_id, topics.topic_subject, topics.topic_date, topics.topic_cat, topics.topic_by, users.user_name, users.avatar, categories.cat_id, categories.cat_name FROM topics LE
$sql = "SELECT topics.topic_id, topics.topic_subject, topics.topic_date, topics.topic_cat, topics.topic_by, users.user_name, users.avatar, categories.cat_id, categories.cat_name
FROM topics
LEFT JOIN users ON topics.topic_by=users.user_id
LEFT JOIN categories ON categories.cat_id=topics.topic_cat
WHERE topics.topic_cat = " . mysql_real_escape_string($_GET['id']) . " ORDER BY topics.topic_date DESC;";
这将用户头像放在主题帖子上,现在我试图应用到回复/主题线程,但它不起作用,下面是我使用的代码
$posts_sql = "SELECT
posts.post_topic,
posts.post_content,
posts.post_date,
posts.post_by,
users.user_id,
users.user_name,
users.avatar
FROM
posts
LEFT JOIN users
ON
posts.post_by = users.user_id
WHERE
posts.post_topic = " . mysql_real_escape_string($_GET['id']);
我不确定我做错了什么,但它正在打破这一页
...... WHERE posts.post_topic = " . mysql_real_escape_string($_GET['id'])
在这里,您似乎正在尝试按主题搜索,但使用ID。因此没有找到任何内容。查询不会断开页面,但输出到页面会断开页面…页面会返回结果,而不是“化身”,但它已加载所有其他信息。mysql是否会从db返回化身值,而只是不显示?或者db为头像返回空值?无论如何,发布获取和处理数据库结果的全部代码$posts\u sql=“选择posts.post_主题、posts.post_内容、posts.post_日期、posts.post_by、users.user_id、users.user_name、users.avatar从帖子左侧加入posts.post_by=users.user_id WHERE posts.post_主题=“.mysql_real_escape_字符串($\u GET['id'))$posts\u result=mysql\u query($posts\u sql);这是完整的代码吗?mysql\u fetch\u()或类似的数据提取在哪里?$posts\u sql=“选择posts.post\u主题,posts.post\u内容,posts.post\u日期,posts.post\u by,users.user\u id,users.user\u名称,来自帖子左侧的users.avatar在posts.post_by=users.user_id WHERE posts.post_topic=“.mysql_real_escape_string($_GET['id']);$posts_result=mysql_query($posts_sql);如果(!$posts_result){echo'无法显示帖子,请稍后再试。;}否则{while while($posts_row=mysql_fetch assoc)($posts_result)){include(“includes/new reply.php”);}