Jump to content

Send alerts based on mysql date


ampsman

Recommended Posts

Yes, I have done things like this many times.  Typically you write the php script that you call from a cron job which runs it on a set schedule, using command line php:

 

php -f checkfornotify.php

 

I have written several articles on using the various date columns along with builtins to determine date ranges offset from right now:

 

http://www.gizmola.com/blog/archives/51-Exploring-Mysql-CURDATE-and-NOW.-The-same-but-different..html

http://www.gizmola.com/blog/archives/99-Finding-Next-Monday-using-MySQL-Dates.html

 

 

What is your specific question?

so I think I am getting closer.

something like this will find any records that have a date 3 days away.

 

$result = 'SELECT * FROM emp_info WHERE StartDate = DATE_ADD(curdate(), INTERVAL 3 DAY);'

 

Yes something like that will work if StartDate is a DATE column.  If it's a DATETIME, you have to be concerned with the time component -- if not looks like you're on your way.

 

 

woohoo!!!

got it working!

Here is the final code for anyone with the same question.

<?php
$username = "username";
$password = "password";
$hostname = "localhost"; 

//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password) 
or die("Unable to connect to MySQL");

//select a database to work with
$selected = mysql_select_db("db_name",$dbhandle) 
  or die("Could not select examples");

//execute the SQL query and return records
$result = mysql_query("SELECT * FROM table WHERE date_field = DATE_ADD(curdate(), INTERVAL 3 DAY)");

//fetch tha data from the database 
while ($row = mysql_fetch_array($result)) {
   mail("[email protected]", "Subject", "body");
}
//close the connection
mysql_close($dbhandle);
?>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.