MySQL从今天开始提前一周找到所有行

时间:2015-10-29 13:38:30

标签: mysql date

我试图在发布之前在Stackoverflow上找到一个MySQL代码片段,但结果却没有结果。

我有一个代码,我需要显示所有"项目"仅在8天后发布。例如,我们是10-29-2015。 MySQL将返回创建日期为10-21-2015的项目。 2015年10月22日的物品不应计算在内。

到目前为止,我的MySQL查询逻辑看起来像:

  

SELECT * FROM my_table WHERE 日期早7天,低于9天

在我的MySQL结构中,字段 start_date 的类型为日期

我认为最好的办法是做这样的事情:

WHERE TODAY = start_date + 7 DAYS  

EDIT1:根据给定的评论,我的查询应该是:

SELECT * FROM `my_table` WHERE `start_date` = CURDATE() - INTERVAL 8 DAY;

1 个答案:

答案 0 :(得分:1)

尝试:

<?php
ignore_user_abort(true);

set_time_limit(0); // disable the time limit for this script

$path = "toDownload/"; // change the path to fit your websites document structure
$dl_file = $_GET['download_file']; // simple file name validation
$fullPath = $path.$dl_file;
if ($fd = fopen ($fullPath, "r"))
{
    $fsize = filesize($fullPath);
    $path_parts = pathinfo($fullPath);
    $ext = strtolower($path_parts["extension"]);
    switch ($ext) 
    {
        case "txt":
        header("Content-type: application/txt");
        header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\""); // use 'attachment' to force a file download
        break;
        // add more headers for other content types here
        default;
        header("Content-type: application/octet-stream");
        header("Content-Disposition: filename=\"".$path_parts["basename"]."\"");
        break;
    }

    header("Content-length: $fsize");
    header("Cache-control: public"); //use this to open files directly

    while(!feof($fd))
    {
        $buffer = fread($fd, 2097152); // 2097152 Octet = 2Mo
        echo $buffer;
    }
}
fclose ($fd);
exit;
?>