gpt4 book ai didi

php - 如何显示mysql每个类别的最新条目

转载 作者:行者123 更新时间:2023-11-30 00:37:00 25 4
gpt4 key购买 nike

我们正在使用CodeIgniter,我们希望在(published_date)之前获得6个类别的最新10个条目,然后我们将在 View 中显示不同类别的结果。在这里,我们使用 6 个彩色框来显示每个类别的 10 个最新条目。我们的 SQL 表看起来像这样...

-> ci_categories

cat_id | cat_name | cate_slug  | cate_title

-> ci_pages

page_id  | cat_id | page_title  | published_date
--------------------------------------
1 | 1 | Ttl 1 | 2014-02-22 10:22:20
2 | 2 | Ttl 2 | 2014-02-24 11:42:30
3 | 1 | Ttl 3 | 2014-02-26 10:37:21
4 | 3 | Ttl 3 | 2014-02-28 12:40:30

最佳答案

SELECT `ci_pages`.`cat_id` AS CAT_ID,
(SELECT `cat_name` FROM `ci_categories` WHERE `ci_categories`.`cat_id` = `ci_pages`.`cat_id`) AS CAT_NAME,
(SELECT `cat_slug` FROM `ci_categories` WHERE `ci_categories`.`cat_id` = `ci_pages`.`cat_id`) AS CAT_SLUG,
(SELECT `cat_title` FROM `ci_categories` WHERE `ci_categories`.`cat_id` = `ci_pages`.`cat_id`) AS CAT_TITLE
FROM `ci_pages`
ORDER BY `ci_pages`.`published_date` DESC
LIMIT 10;

这会将最后插入的 10 个值返回到“ci_pages”表中,并从“ci_pages”表中获取每个类别的详细信息。现在检查...

关于php - 如何显示mysql每个类别的最新条目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22088275/

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