Jump to content

Query database and E-mail the query result


Person

Recommended Posts

Updated script

 

I need to Query the DB and then E-mail the information in a mail from the code to an E-mail address

 

$host = "localhost";
$user = "XXXX_pnke2";
$pass = "XXXX";
$dbname = "XXXXX_pnke2";

$con = mysql_connect($host,$user,$pass) or die (mysql_errno().": ".mysql_error()."<BR>");
mysql_select_db($dbname);

$query= "SELECT SUM(1) AS clicks, SUM(`clcpc`), SUM(`chcpc`) FROM `nuke_pnAffiliate_clicktracking` WHERE `pl` = 'rpu' AND  `date` = '20070418'";
echo $query;

$result= mysql_query($query);
$num_results = mysql_num_rows($result);

for ($i=0; $i <$num_results; $i++)
{
$row = mysql_fetch_array($result);
echo "Clicks: ", $row['user_id'],";
}

?>

<?php 
$email_to = "[email protected]";
$email_from = "XXXXX server do not reply";
$email_title = "Total Clicks report";
$email_body =Dear $user,

$result= mysql_query($query);

Thank you,
XXXXXX Site;
   $success = mail($to,$from,$title,$body,
              "From:$from\r\nReply-To:XXXXXX server do not reply");

?>

 

If someone could help me out... im new to this.

 

Regards

OK heres a basic untested and incomplete example

 


<?php 
$result= mysql_query($query);
while ($row=mysql_fetch_array($result))
{
$user = $row['user']; //<---get the idea

$email_to = "[email protected]"; //<--See above for example
$email_from = "XXXXX server do not reply";
$email_title = "Total Clicks report";
$email_body ="Dear $user,
Thank you,
XXXXXX Site";
   $success = mail($email_to,$email_from,$email_title,$email_body,
              "From:$email_from\r\nReply-To:XXXXXX server do not reply");
} 
?>

 

 

as a note you may need to clean up the code as your not pulling the fields you need from the database (see your select statement)

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.