按日期范围查询 [英] Query by Date Range

查看:77
本文介绍了按日期范围查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello theScripts,我一直在这里使用很多教程和论坛,所以我觉得是时候加入了。我发现这里的一切都没什么,只有帮助。


我想知道你们是否能帮我一臂之力。 (如果这是假设在MySQL论坛中我提前道歉)。


我正在努力做一个学校闭幕提醒学校网站,比如下雪时。差不多,我为秘书做了一个简单的表格来输入标题和内容。她的信息进入一个MySQL表(名为''alert''),其中包含字段标题,内容,日期时间(设置为auto_update的时间戳)和id(auto_increment)。


差不多,我希望查询查看表格,如果今天放入了某些内容,请在网站上用conent制作div。如果没有投入,它就不会成为一个div。简单。


不知何故,我需要查询来检查今天午夜到晚上11:59之间是否有帖子。因此,一旦明天午夜到来,它就找不到任何东西。


我有这个概念


[PHP]


<?php

$ today = date(" j,n,Y");

$ query = mysql_query(" SELECT * FROM`warning` WHERE datetime = $ today ORDER BY`id`DESC LIMIT 0,1");

while($ row = mysql_fetch_array($ query)){

echo''< div id =" alert" style =" background:red; border:2px solid#000;">< h1>''。$ row [''Title'']。'' - ''。$ row [''datetime'' ]。''< / h1>< p>''。$ row [''提醒'']。''< / p>< / div>'';

}

?> [/ PHP]


现在在这里应该有用,不用说......它不是。我将限制设置为第一个ID,因为如果她想对当前警报进行更改,那么她所要做的就是重新输入并选择最顶层的警报。


让我知道你们这一切,并提前感谢。

Hello theScripts, i''ve been using a lot of tutorials and forum reads here, so i figured it was time i joined. I''ve found everything here nothing but helpful.

I was wondering if you all could give me a hand on this. (if this is suppose to be in MySQL forum i apologize in advance).


I''m trying to make a "School Closing" alert for a school website, like when it snows. Pretty much, I made a simple form for a secretary to input into with a title and content. Her info goes into a MySQL table (named ''alert'') with the fields title, content, datetime (which is set to timestamp with auto_update), and id (auto_increment).

Pretty much, i want the query to look at the table, if something was put in today, make a div on the site with the conent. If nothing was put in, it wont make a div. Simple.

Somehow, i need the query to check if the post was put in today between midnight and 11:59pm today. So once midnight hits tomorrow, it won''t find anything.

I had this concept

[PHP]

<?php
$today = date("j, n, Y");
$query = mysql_query("SELECT * FROM `alert` WHERE datetime = $today ORDER BY `id` DESC LIMIT 0 , 1");
while($row = mysql_fetch_array($query)) {
echo ''<div id="alert" style="background:red;border:2px solid #000;"><h1>''.$row[''Title''].'' - ''.$row[''datetime''].''</h1><p>''.$row[''Alert''].''</p></div>'';
}
?>[/PHP]


Now in thereory this should work, needless to say...it isn''t though. I have the limit set to the first id because if she wanted to make a change to the current alert, all she has to do is retype and it will pick the top one.


Let me know what you all this, and thanks in advance.

推荐答案

今天=日期( j,n,Y);
today = date("j, n, Y");


query = mysql_query(" SELECT * FROM`warning` WHERE datetime =
query = mysql_query("SELECT * FROM `alert` WHERE datetime =


今天ORDER BY`id` DESC LIMIT 0 ,1")

while(
today ORDER BY `id` DESC LIMIT 0 , 1");
while(


这篇关于按日期范围查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆