gpt4 book ai didi

php - 如何排除最后3个id并从mysql php数据库中提取内容?

转载 作者:行者123 更新时间:2023-11-29 22:03:51 25 4
gpt4 key购买 nike

我需要从同一个表中提取上半部分的最新 3 篇帖子(带内容)和下半部分的其余部分(仅标题)。我在上半部分摘录了三篇最新的帖子。但在下部,上部的标题也重复。我不需要显示上部的标题。我的代码是这样的:

上部代码

    $fetch_sql = "SELECT fld_news_id, fld_news_name, fld_news_details FROM table_news ORDER BY fld_news_id DESC LIMIT 3";
$fetch_result= mysql_query($fetch_sql) or die(mysql_error());
while($fetch_row=mysql_fetch_array($fetch_result))
{
$fld_news_id = $fetch_row['fld_news_id'];
$fld_news_name = $fetch_row['fld_news_name'];
$fld_news_details = $fetch_row['fld_news_details'];
echo"<h3> $fld_news_name </h3>";
echo"$fld_news_details";
}

下部代码

    $fetch_sql = "SELECT fld_news_id, fld_news_name FROM table_news ORDER BY fld_news_id DESC LIMIT 10";
$fetch_result= mysql_query($fetch_sql) or die(mysql_error());
while($fetch_row=mysql_fetch_array($fetch_result))
{
$fld_news_id = $fetch_row['fld_news_id'];
$fld_news_name = $fetch_row['fld_news_name'];
echo"<h3> $fld_news_name </h3>";
}

最佳答案

在下部使用以下查询:

SELECT fld_news_id, 
fld_news_name
FROM table_news
WHERE fld_new_id NOT IN(SELECT *
FROM (SELECT fld_news_id
FROM table_news
LIMIT 3) AS t)
ORDER BY fld_news_id DESC
LIMIT 10

Description: I am excluding result of first query from second.

关于php - 如何排除最后3个id并从mysql php数据库中提取内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32353963/

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