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?

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

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("xxxx@xxx.com", "Subject", "body");
}
//close the connection
mysql_close($dbhandle);
?>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.