jason filled out the form and wants e-mails at 09:00, 18:00
nay filled out the form and wants e-mails at 07:00, 18:00
bech filled out the form and wants e-mails at 12:00, 23:00
now at the moment im looking into storing these into MySQL in the following fields:
- time1
- time2
- time3
- time4
- time5
now that isnt a problem at all, the problem i am having is that the script is called by a cron job at the hour, every hour. so i need to create an if statement that basically is:
Code: Select all
// pseudo
if (current time is 03:00);
{
//send mails to users with 03:00 in the database
}i have something like this in mind:
Code: Select all
<?php
require("some_other_pages.php");
// first we need to get the time
// i will be only adding the leading char's
// so it easier for the script to work with
// and stop errors for eg 23 = 11pm
$time = time("G");
// lets start the query and data extraction
$query = "SELECT * FROM users WHERE time1 OR time2 OR time3 OR time4 OR time5 = $time";
// now actually run the query
$result = mysql_query($query) or die(mysql_error());
// now lets get the resulting data from the database (mysql)
$row1 = mysql_fetch_array($result, MYSQL_ASSOC);
// now lets get the num rows so we can create a more
// resource friendly script
$number = mysql_num_rows($result);
// ok we have the time now we should start making the
// if / elseif statements
if ($time == 1)
{
// $subject + $message, would be defined elsewhere in
// an inc page
mail("$row1[email]", "$subject", "$message");
// now we need to loop through the results in case
// theres more than one
if ($number >= 1)
{
while ($row2 = mysql_fetch_assoc($result))
mail("$row2[email]", "$subject", "$message");
}
}
// i would do the same for the other if statements
// if (time == 4) etc etcand is there anyway i could improve teh script?