|
Posted by paul814 on 12/21/07 17:56
I've been working on this for some time now and have gotten
nowhere...hoping someone here can help.
I want to take and email all records in a database for the current
date when this php page is run.
Now I have a number of tables in this database...looking like this:
editorial
editorialdate, editorialname, editorialcomments
press
pressdate, pressname, presscomments
mail
maildate, mailname, mailcomments
So what I want to do is take anything for $today and put it into an
email, the email would look like this:
==
Editorial Report:
editorialdate
editorialname
editorialcomments
Mail Report:
maildate
mailname
mailcomments
etc...
here is what I have now, wich I thought would do it:
Generating and emailing report for:
<?php
$today = date("M j, Y,");
echo $today;
$host="localhost";
$user="root";
$pass="";
$db="productiondb";
$con = mysql_connect($host, $user, $pass);
if (!$con)
{
die('Unable to connect: ' . mysql_error());
}
mysql_select_db($db, $con) or die('Unable to connect: ' .
mysql_error());
$sql = "SELECT * FROM editorial WHERE editorialdate LIKE '$today%' ";
$result = mysql_query($sql,$con); // actually runs the query
if (mysql_num_rows($result)) { // if there are results
while ($row = mysql_fetch_array($result)) { // puts the values into
$row
print $row->editorialdate;
print $row->editorialname;
print $row->editorialcomments;
}
}
//this part sends email
ini_set("SMTP", "texchange.company.com");
ini_set("smtp_port", "25");
$to = "paul@company.com";
$subject = "Production report";
$txt = "$row[0] \n\r\n\rPLEASE DO NOT REPLY TO THIS EMAIL, THIS IS NOT
A VALID EMAIL ADDRESS";
$headers = "From: Daily_Prod._Report@company.com";
mail($to,$subject,$txt,$headers); # <--- sends the email
mysql_close($con); //closes the connection to the DB
?>
my $today works fine because at the very beginning it will say:
Generating and emailing report for: Dec 21, 2007,
So I know it is getting the right date....so I am trying this for one
table in my DB now....and all I get is a blank email with no data in
it from my database.
Anyone have any ideas?
Navigation:
[Reply to this message]
|