简体   繁体   English

在画廊中显示一些带有日期的图像

[英]Showing some images at gallery with date

Bro, I have a php project to display some images.兄弟,我有一个 php 项目来显示一些图像。 The image is uploaded automatically from a folder every 10 minutes interval.图像每隔 10 分钟从文件夹自动上传一次。 There is an image that goes into that folder but the image displayed is only uploaded every 1 hour, and the image that appears is the last image goes to that folder.有一个图像进入该文件夹,但显示的图像仅每 1 小时上传一次,出现的图像是该文件夹中的最后一张图像。 Can you help me?你能帮助我吗?

My code is:我的代码是:

`include 'connect.php';'   

$sql = "SELECT * FROM tbl_album where albumid='$aid'";    
$rs_result = mysql_query ($sql,$con);           
while ($row = mysql_fetch_assoc($rs_result))     
{    
$aimage=$row['image'];    
$aname=$row['name'];    
$adesc=$row['adesc'];    
$astatus=$row['status'];

You should definitely provide more information, but I'm going to take a guess that the issue is with your query not having an ORDER BY statement.您绝对应该提供更多信息,但我将猜测问题在于您的查询没有 ORDER BY 语句。

SELECT * FROM tbl_album where albumid='$aid'

Without knowing the column names in your table it's difficult to tell you how to fix it, but let's assume you have you have a datetime column called "uploaded_dt" that is accurately populated upon upload.在不知道表中的列名的情况下,很难告诉您如何修复它,但假设您有一个名为“uploaded_dt”的日期时间列,该列在上传时准确填充。

You'd change your query then to the following:然后您将查询更改为以下内容:

SELECT * FROM tbl_album WHERE albumid='$aid' ORDER BY uploaded_dt DESC

ADDITIONALLY & IMPORTANTLY额外且重要的

Please do not use mysql* functions.请不要使用 mysql* 函数。 You're opening yourself up to SQL injection problems.您正在向 SQL 注入问题敞开心扉。

Please learn about PDO before you do anything else.在做任何其他事情之前,请先了解 PDO。

Doing this query 'properly' with PDO would look like this:使用 PDO“正确”执行此查询将如下所示:

$q = $dbh->prepare ('SELECT * FROM tbl_album WHERE albumid = :albumid ORDER BY uploaded_dt DESC');
$q->bindValue ('albumid', $aid);
$q->execute();

while ($r = $q->fetch()) {
  /* all your code here */
}

Now you just need to post more information about your uploading issue so we can help with that.现在,您只需要发布有关上传问题的更多信息,我们就可以提供帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM