Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP to CSV not outputting fields correctly
    primarykey
    data
    text
    <p>I am trying to output my PHP code to a downloadable CSV file and so far i am able to do this however at the moment, the output does not place the field data into separate columns. Instead it puts everything into one column and in addition to that, it displays the postcodes in its neighbouring columns. Does anyone know why this is?</p> <pre><code>&lt;?php header("Content-type: text/csv"); header("Cache-Control: no-store, no-cache"); header('Content-Disposition: attachment; filename="filename.csv"'); $outstream = fopen("php://output",'w'); if ($db_found) { // Select all fields from bodyshops_master_network table $SQL = "SELECT * FROM bodyshops_master_network"; $result = mysql_query($SQL); while ( $db_field = mysql_fetch_assoc($result) ) { // Splits the arrays $row = explode(",", $db_field['postcodes_covered']); $dealer_code = $db_field['dealer_code']; $dealer_name = $db_field['dealer_name']; $bodyshop_id = $db_field['bodyshop_id']; $bodyshop_name = $db_field['bodyshop_name']; $address1 = $db_field['address1']; $address2 = $db_field['address2']; $address3 = $db_field['address3']; $address4= $db_field['address4']; $address5 = $db_field['address5']; $postcode = $db_field['postcode']; $bo_tel = $db_field['BO_tel']; $bo_email = $db_field['BO_email']; $bc_name = $db_field['BC_name']; $equity_contract = $db_field['equity_contract']; echo "&lt;pre&gt;"; foreach ($row as $value) { echo $dealer_code . " "; echo $dealer_name . " "; echo $bodyshop_id . " "; echo $bodyshop_name . " "; echo $address1 . " "; echo $address2 . " "; echo $address3 . " "; echo $address4 . " "; echo $address5 . " "; echo $postcode . " "; echo $bo_tel . " "; echo $bo_email . " "; echo $bc_name . " "; echo $equity_contract . " "; echo $value. "&lt;BR&gt;"; fputcsv($outstream, $row, ',', '"'); } echo "&lt;/pre&gt;"; } mysql_close($db_handle); } else { print "Database NOT Found "; mysql_close($db_handle); fclose($outstream); } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload