douyou2048 2013-09-10 16:50
浏览 55
已采纳

Drupal查询没有更新

<?php
$search = array('.pdf', '.', '-', '_');
$replace = array('', '/', '</u>- ', ' ');
$query="SELECT  STR_TO_DATE(SUBSTR(`filename`, 1, 10),'%m.%d.%Y') as filedate, `filename`, `filepath`
FROM  `files`  
WHERE `filepath` LIKE 'sites/default/files/news/%' 
ORDER BY filedate DESC
LIMIT 4";
$results = db_query($query);

while ($row = db_fetch_array($results)) {
    echo '<tr>';
    echo '<td><u><a href=http://website.com/sites/default/files/news/'. $row["filename"] . '>' . str_replace($search, $replace, $row["filename"]) . '</a></td><br />';
    echo '</tr>';
}
?>

I have this code on the homepage of my website. It pulls all files in a certain folder that start with a date. Currently, when I add a new file, the query doesn't update, even though when I run the query in PHPmyadmin it works fine.

What's happening to make the query not update itself? Flushing cache's haven't worked for me.

  • 写回答

1条回答 默认 最新

  • drq61040 2013-09-10 18:04
    关注

    First of all, your not trying to update, your pulling data from the database.

    I would suggest you use file_scan_directory.

    https://api.drupal.org/api/drupal/includes!file.inc/function/file_scan_directory/7

    <?php
    $files = file_scan_directory('/sites/default/files/news', '/.*\.pdf$/');
    foreach ($files as $file) {
      print $file->filename;
    }
    ?>
    

    Above code is not directly tested.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何将下列的“无限压缩存储器”设计出来
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭