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.
10 2641
whats the data type of 'datetime'?
If the type is datetime, I think you need to do this:
[PHP] $today = date("Y-m-d H:i:s");[/PHP]
[link removed]
the data type is timestamp.
If its a unix timestamp use the php time() function or the mysql function of UNIX_TIMESTAMP()
thanks, but what am i actually doing to set a range, from midnight to 11.59pm?
use something like (UNIX_TIMESTAMP()+(60*60*24))
Heya, Record LL.
On the PHP side, you can build your two datetimes like this: -
$thisMorning = date('Y-m-d 00:00:00');
-
$thisEvening = date('Y-m-d 11:59:59');
-
-
// Or, for maximum efficiency...
-
$today = date('Y-m-d');
-
$thisMorning = $today . ' 00:00:00';
-
$thisEvening = $today . ' 11:59:59';
-
Then, using the MySQL BETWEEN keyword, it becomes reasonably easy to find the events of the day: -
$_sql = "
-
SELECT
-
*
-
FROM
-
`alert`
-
WHERE
-
(
-
`datetime`
-
BETWEEN
-
'{$thisMorning}'
-
AND
-
'{$thisEvening}'
-
)
-
ORDER BY
-
`id` DESC
-
LIMIT 1";
-
thanks alot, im still new to the whole "date formatting thing". im gonna try this out as soon as i can. thanks for the help all.
just an update, that worked. thank you
Heya, LL.
Glad to hear you got it working! Good luck with your project, and if you ever need anything, post back anytime :)
[Query by Date Range - First post here.]
Removed some unnecessary words from the thread title.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Got2Go |
last post by:
Hello Group,
I have a table that has 3 columns:
ID (int), datetime, Value(varchar)
ID = ID for the SNMP device
datetime = time record was added
value = value added for that device.
This...
|
by: Mike Cooper |
last post by:
Hi everyone,
This is a tough one. I have a database full of solicitations,
identifying a customer and recording initial call, first followup,
second followup, etc.
My boss want to be able to...
|
by: Don Sealer |
last post by:
I'm guessing this is pretty simple however not simple enough for me.
I'm developing a database to track expenses, income, banking
transactions, etc.
I have a very simple query with four fields,...
|
by: sixdeuce62 |
last post by:
Hello,
I am trying to create a query that will prompt me to enter the
parameter value if beginning date and ending date.
I have created everything I need in the query, but I have to manually
go...
|
by: jennwilson |
last post by:
Using Access 2000 - I have a query that is suppose to return the records from table within specified time range and find matching data from another table .
Table houses Clinician name, location...
|
by: QCLee |
last post by:
Sir can you help me to transfer my Access Query to MS excel? i have a
command button on the form to export the parameter query named
"HVACWindwardQuery" to excel spreadsheet and i got the codes...
|
by: Sandboxer |
last post by:
I want to be able to program Access to provide for me, by individual day, what my contract obligations are to my customers. Will Access recognize all the individual days in between a date range...
|
by: lindabaldwin |
last post by:
Hello everyone,
I am fairly new to VBA. I have a worksheet in Excel, named "Data Sheet" from which I am trying to query data. This worksheet contains the following data: unit (column A), date...
|
by: lenygold via DBMonster.com |
last post by:
Hi everybody!
This query is supposed to count consecutive years from the current year
without OLAP.
Input Table:
ID DateCol
1 02/01/2006
1 01/01/2006
1 01/01/2005
|
by: phill86 |
last post by:
Hi
I am re-posting this thread because it has become very confusing and I have got some way to solving the problem so it is a slightly different question from the initial thread.
here is the...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
| |