$header = "product_id,sku,name,cost,rrp,our_price,sale_price,clearance_price,supplier_gross_price,supplier_net_price\n"; $data = $header; $sql = "SELECT * FROM products ORDER BY product_id ASC"; $rs = mysql_query($sql); while($row = mysql_fetch_assoc($rs)){ $data .= $row['product_id'].",".$row['sku'].",".$row['name'].",".$row['cost'].",".$row['rrp'].",".$row['our_price'].",".$row['sale_price'].",".$row['clearance_price'].",".$row['supplier_gross_price'].",".$row['supplier_net_price']."\n"; } $file_name = "product_price.csv"; ob_clean(); echo $data; header("Content-type: application/csv"); header("Content-Disposition: attachment; filename=$file_name"); header("Pragma: no-cache"); header("Expires: 0");