gpt4 book ai didi

php - 跨表查询

转载 作者:行者123 更新时间:2023-11-29 14:45:40 24 4
gpt4 key购买 nike

我正在运行一个查询来检索用户帖子。表“帖子”有一列包含提交帖子的用户的姓名,另一个名为“用户”的表也有用户名和头像列表。

我需要在表 Users 上的每篇文章中查找“User”,以及该表中是否存在匹配的回显列“Avatar”。

$result = mysql_query("SELECT * FROM Posts WHERE MATCH (City) AGAINST ('$city2') ORDER by `Comments` DESC LIMIT $limit_posts OFFSET $first_post");

while($row = mysql_fetch_array( $result )) { ?>
<div class='item'>
<a href="?city=<?php echo $row['City']; ?>&post=<?php echo $row['PID']; ?>"><?php echo $row['Text']; ?></a>
<? }

最佳答案

$result = mysql_query("
SELECT
Posts.*,
Users.Avatar
FROM
Posts
INNER JOIN
Users
ON
Users.ID = Posts.User
WHERE
MATCH (Posts.City) AGAINST ('$city2')
ORDER BY
Posts.`Comments` DESC
LIMIT
$limit_posts
OFFSET
$first_post
");

while($row = mysql_fetch_array( $result )) { ?>
<div class='item'>
<a href="?city=<?php echo $row['City']; ?>&post=<?php echo $row['PID']; ?>"><?php echo $row['Text']; ?></a>

<?php echo $row['Avatar']; ?>
<? }

关于php - 跨表查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7005563/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com