dongyou5098 2017-04-21 02:03
浏览 58

如何从下往上加载数据库图像/文本? (最新帖子第一)

I have code in which a user can upload a file/image and text, and then it displays onto the page. I would like for the newest uploaded posts to show first and oldest last, so basically from the bottom up. Here is my code where I am loading it normally:

PHP/SQL:

<?php
$db = mysqli_connect("localhost", "", "", "boxofmem_GMSConnect");
$sql = "SELECT * FROM images";
$result = mysqli_query($db, $sql);
while ($row = mysqli_fetch_array($result)) {
    echo "<div id='img_div'>";
    echo "<p style='font-family:Roboto;color:white;font-size:20px;'>".$row['text']."</p>";
    echo "<img src='images/".$row['image']."' ' style='width:100%;height:100%;'>";
    echo "</div>";
}

?>

FIELDS:

ID (int:11) IMAGE (BLOB) TEXT (TEXT)

  • 写回答

2条回答 默认 最新

  • dongyinting3179 2017-04-21 02:04
    关注

    If you mean the reverse order, that’s done in SQL:

    SELECT * FROM images ORDER BY something DESC
    

    where something is the actual field you want to sort. It may be the primary key or a date.

    In your case, the ID column appears to be the primary key, and is probably auto-incremented. That means recent records have higher values. To display the most recent first:

    SELECT * FROM images ORDER BY ID DESC
    

    the ORDER BY clause, which is optional, but always the last clause of an SQL statement, determines the sort order. The default order is ascending ASC, and is implied if you don’t specify a direction.

    DESC reverses the order. This will bring the most recent to the top.

    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度