【问题标题】:Show Every Data from Mysql Database except the last one [duplicate]显示Mysql数据库中的所有数据,除了最后一个[重复]
【发布时间】:2016-03-27 22:43:16
【问题描述】:
$query = "SELECT id,subject,date,notice from sam_notice ORDER BY id DESC LIMIT 1";$result = $conn->query($query);

这个查询只提取最后一个,我可以在第 1 节中查看

$query2 = "SELECT id,subject,date,notice from sam_notice ORDER BY id DESC";$result2 = $conn->query($query2);

此查询提取所有数据以在第 2 节中查看

我需要在 query2 中进行什么更改,以便它可以提取除最后一个之外的所有数据?

【问题讨论】:

  • 嗨@User:您没有回复任何答案。

标签: php mysql web


【解决方案1】:

如果,id 列是 primary keyauto-incremented

$query2 = "SELECT id,subject,date,notice 
           FROM sam_notice 
           WHERE id < (SELECT MAX(id) FROM sam_notice)";

【讨论】:

    【解决方案2】:

    试试

    SELECT id,subject,date,notice 
     FROM sam_notice
    WHERE id != (SELECT MAX(id) FROM sam_notice
    

    【讨论】:

      【解决方案3】:

      不要寻找 SQL 方式。相反,在使用结果时只需跳过第一行(这是自您使用DESC 以来的最后一行)。像这样的:

      $query2 = "SELECT id,subject,date,notice from sam_notice ORDER BY id DESC";
      $result2 = $conn->query($query2);
      $begin = TRUE;
      while ($row = <some fetch method on $result2, depending on your current API>) {
        if($begin) {
          $begin = false;
          continue;
        }
        // use other rows...
      }
      

      【讨论】:

        猜你喜欢
        • 2018-03-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-11-08
        • 1970-01-01
        • 2020-04-26
        • 2015-10-09
        • 1970-01-01
        相关资源
        最近更新 更多