gpt4 book ai didi

PHP MySQL 查询 : Get category name based on post id?

转载 作者:行者123 更新时间:2023-11-29 07:28:51 24 4
gpt4 key购买 nike

帖子表:

id | name              | category_id
1 | Some article name | 3

类别表:

id | name
3 | Some Category name

...

$sql = '';

$query = DB::query($sql, $post_id);

foreach ($query as $row){
$category_name = $row["name"];
}

$sql 应该包含什么来完成查询?

最佳答案

SELECT c.name
FROM posts p
INNER JOIN categories c ON c.id = p.category_id
WHERE p.id = ...

关于PHP MySQL 查询 : Get category name based on post id?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33503301/

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