php - How to export to csv with concatenated columns -
i want export mysql data csv file concat 4 columns,but not work can 1 me asap want concat add1,add2,add3,city,pincode these columns , shows in single column in csv file
thnx in advance
my php code follows
<?php require_once("config.php"); //enter headings of excel columns $contents="sr no,date,agent name,process,donar name,address,contact no,nearest station,suburbans,pickup time,confirmation status,pickup amount,field executive\n"; //mysql query records datanbase //you can customize query filter particular date , month etc...which depends database structure. $sr_no=$_get['sr_no']; $dt=date('y-m-d'); $user_query = mysql_query("select sr_no,entry_date,agent_name,process_name,donar_name,concat( ifnull( add1, '' ) , ' ', ifnull( add2, '' ) , ' ', ifnull( add3, '' ),' ',ifnull( city, '' ),'', ifnull( pincode, '' ) ) full_address,mobile_no,nearest_station,suburbans,pickup_time,confirmation_status,pickup_amount,field_executive leads entry_date='$dt'"); //while loop fetch records while($row = mysql_fetch_array($user_query)) { $contents.=$row['sr_no'].","; $contents.=$row['entry_date'].","; $contents.=$row['agent_name'].","; $contents.=$row['process_name'].","; $contents.=$row['donar_name'].","; $contents.=addslashes($row['full_address']).","; //$contents.=$row[{['add1']}{$row['add2']}{$row['add3']}].","; $contents.=$row['mobile_no'].","; $contents.=$row['nearest_station'].","; $contents.=$row['suburbans'].","; $contents.=$row['pickup_time'].","; $contents.=$row['confirmation_status'].","; $contents.=$row['pickup_amount'].","; $contents.=$row['field_executive']."\n"; } // remove html , php tags etc. $contents = strip_tags($contents); //header make force download file header("content-disposition: attachment; filename=leads for".date('d-m-y').".csv"); print $contents; ?>
change this:
$contents.=$row[{['add1']}{$row['add2']}{$row['add3']}].",";
to this:
$contents.="{$row['add1']}{$row['add2']}{$row['add3']},";
Comments
Post a Comment