php - mysql query to excel -
community,
i working on report builder. objective of report builder send out email excel document weekly information coming sql table. activated when first person logs in day on monday. if monday holiday, , no 1 logs in day, timestamp not made in database. when user logs in tuesday, looks @ last timestamp see if 1 placed previous day. if not, fire on tuesday.
the first step in process looks this...
$today = cal_to_jd(cal_gregorian,date("m"),date("d"),date("y")); $yesterday = date('y-m-d', strtotime($date .' -1 day')); $holiday = false; if(jddayofweek($today,1) == 'tuesday') { if(mysql_num_rows(mysql_query("select report_date report_builder report_date = '{$yesterday}'")) == 0) { $holiday = true; } } if(jddayofweek($today,1) == 'monday' || $holiday === true) { $today = mysql_query("select report_date report_builder report_date = curdate()"); if(mysql_num_rows($today) == 0) { $date = date('y-m-d h:i:s',time()-(7*86400)); mysql_query("insert report_builder (report_date) values (curdate())"); //more code here
**the question particular post follows:
is possible send information csv file not open user can see, instead saved temporary file? can done in way doesn't send background html?**
once accomplished, wanted send file user using current code looks this...
require("class.phpmailer.php"); $mail = new phpmailer(); $mail->from = "**********"; $mail->addaddress("*************"); $mail->subject = "test"; $mail->body = "hi"; $filename = $_files['file']['name']; $tmpname = $_files['file']['tmp_name']; $filename = addslashes($filename); echo $filename; $mail->addattachment("temporary file path"); if(!$mail->send()) { echo 'message not sent.'; echo 'mailer error:'.$mail->errorinfo; }
yes can write files disk , save in number of ways. point might quick way save steps (i.e. not have create file in php) if application server , mysql on same physical host. of course assuming csv file suitable (i.e. don't need use php excel library build xls or xlsx file)
select [fields] outfile '/path/to/file' fields terminated ',' optionally enclosed '"' lines terminated '\n' your_table; this directly create csv @ location path/to/file on machine can sent via php. please note file name must not existing file name approach not allow overwrite existing file.
if mysql host remote or need manipualte data before writing file, suggest looking @ fputcsv() (http://php.net/manual/en/function.fputcsv.php) in order write data query directly file in csv format.
$file = fopen('/path/to/file.csv', 'w'); while ($row = [your database fetch here]) { fputcsv($file, $row); }
Comments
Post a Comment