Person Posted May 3, 2007 Share Posted May 3, 2007 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 = "XXXXXXX@XXXX.com"; $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 Quote Link to comment https://forums.phpfreaks.com/topic/49734-query-database-and-e-mail-the-query-result/ Share on other sites More sharing options...
MadTechie Posted May 3, 2007 Share Posted May 3, 2007 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 = "XXXXXXX@XXXX.com"; //<--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) Quote Link to comment https://forums.phpfreaks.com/topic/49734-query-database-and-e-mail-the-query-result/#findComment-243881 Share on other sites More sharing options...
Person Posted May 3, 2007 Author Share Posted May 3, 2007 could you put it together as one php file, i still dont understand it ... sorry Quote Link to comment https://forums.phpfreaks.com/topic/49734-query-database-and-e-mail-the-query-result/#findComment-243891 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.