php - Export to csv in wordpress and download -
i have table in database , want export csv click on export csv button. using wordpress , have custom table in database
if(isset($_post['btnmonth'])){ $month = $_post['hidmonth']; $userid = $_post['hiduserid']; //$path = testing($month, $userid); $conn = mysql_connect('localhost', 'sensible_bps', 'inception1111'); mysql_select_db('sensible_bps', $conn); $filename = "toy_csv.csv"; $fp = fopen('php://output', 'w'); if($month == 'all'){ $query= "select * clientsdata client_id = '".$userid."'"; }else{ $query= "select * clientsdata client_id = '".$userid."' , month = '".$month."'"; } $result = mysql_query($query); while ($row = mysql_fetch_row($result)) { $header[] = $row[0]; } header('content-type: application/csv'); header('content-disposition: attachment; filename='.$filename); fputcsv($fp, $header); $query= "select * clientsdata client_id = '".$userid."'"; $result = mysql_query($query); while($row = mysql_fetch_row($result)) { fputcsv($fp, $row); } exit; }
but code not working please solve thanx
Comments
Post a Comment