Forum Moderators: coopster
<?php
$date = date("m/d/Y");
$link = mysql_connect("localhost","******", "*****") or die ("couldnt connect: " . mysql_error());
mysql_select_db("eqoagui_nuke1",$link) or die ("couldnt select db: " . mysql_error());
$results = mysql_query("SELECT * FROM nuke_item_database",$link);
$myrow = mysql_fetch_array($results);
$today = "myrow[date]";
if ($today == "$date") {
do {
$items = "<a href=\"modules.php?name=$module_name&file=item_page&id=$row[id]\"><b>".$row["Item_Name"]."</b></a>\n";
}
while ($myrow = mysql_fetch_array($results));
$myemail = "me@me.com";
mail("$myemail", "Daily updates to your database.", $items,
"From: mysite.com\r\n" .
"Reply-To: none\r\n" .
"X-Mailer: PHP/" . phpversion());
}
else {
$myemail = "me@me.com";
mail("$myemail", "No items added today.",
"From: mysite.com\r\n" .
"Reply-To: none\r\n" .
"X-Mailer: PHP/" . phpversion());
}
?>
I am only receiving emails saying that no items were entered, I do not know why.
Also I would like to set up a cron job to run this file but no matter what I do I cannot get the cron to run a php file, thoughts?
[edited by: jatar_k at 10:28 pm (utc) on July 20, 2004]
It's been a busy day.
First off this line looks suspect
$today = "myrow[date]";
That should be
$today = $myrow['date'];
Second of all you'll want to make sure your date formats are similar. It's pretty rare to see dates stored like 7/20/04. Usually in mySQL it 2004-07-20 or a timestamp format.
Now that I've said that have you considered using the WHERE syntax in your SQL query?
SELECT * FROM nuke_item_database WHERE date = CURDATE()
I'm not sure but I think you'll still have to check on the date formatting for this to work. Check out the mySQL manual under Date and Time functions [dev.mysql.com]. This will select only the items with the current date so you don't need to use php to loop through to find them. You only need to check to make sure something is there then loop through just to send emails.
Hope this helps,
Tim
Beware this is totally untested. Good luck.
<?php
$link = mysql_connect("localhost","******", "*****") or die ("couldnt connect: " . mysql_error());
mysql_select_db("eqoagui_nuke1",$link) or die ("couldnt select db: " . mysql_error());
$results = mysql_query("SELECT * FROM nuke_item_database WHERE date = CURDATE()",$link);
if (mysql_num_rows($results)==0) {
$message = "No items added today";
}
else {
$message = "Daily updates to your database\r\n";
while ($row = mysql_fetch_array($results)) {
$message .= "<a href=\"http://www.mysite.com/modules.php?name=" . $module_name . "&file=item_page&id=" . $row['id'] . "\"><b>" . $row['Item_Name'] . "</b></a>\r\n";
}
}
$to = "me@me.com";
$subject = "Daily updates to your database";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=utf-8\r\n";
$headers .= "From: Me <me@mysite.com>\r\n";
$headers .= "Reply-To: none\r\n";
$headers .= "X-Mailer: PHP/" . phpversion();
mail($to, $subject, $message, $headers);
echo "Results have been sent";
?>
One thing, currently it is sending links, what I would like is for it to send the html to me so that I can cut and paste it into a page, I have fooled around with special characters and such but cant seem to get the code right.
I am sure this is very easy I just cant seem to get it right.