Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>OK, you're doing something really weird here. You're outputting content in two ways.</p> <p>First, you output content in the normal way using <code>echo</code>. Fair enough!</p> <p>Second, you output content using <code>fputcsv</code> where the file handler leads to <code>php://output</code>. Also fair enough!</p> <p>But you shouldn't do both and expect it to work seamlessly. You want a CSV file, so the best way is to output all your data using <code>fputcsv</code>. At the moment, some of your data is encapsulated as a CSV file, and some of it isn't. This leads to output that you don't really want.</p> <p>I <em>think</em> you want something like this:</p> <pre><code>foreach ($row as $value) { $output = array( $dealer_code, $dealer_name, $bodyshop_id, $bodyshop_name, $address1, $address2, $address3, $address4, $address5, $postcode, $bo_tel, $bo_email, $bc_name. $equity_contract, $value ); fputcsv($outstream, $output, ',', '"'); } </code></pre> <p><code>fputcsv</code> expects the data to be an array, so that's what we give it. The separate array fields will be separate columns in the CSV output. We don't <code>echo</code> any data: we store it in an array and then supply it to <code>fputcsv</code>.</p> <p>The second mistake you made was to send <code>$row</code> rather than <code>$value</code> to <code>fputcsv</code>. This meant that you were sending all the postcodes as received from the database row.</p> <p>Finally, you don't need <code>&lt;pre&gt;</code>.</p> <p>On a separate note, you <em>really</em> should have a better database structure. If you had a table of postcodes and a <em>separate</em> table of bodyshops and a foreign key linking them, the code to retrieve data would be a lot simpler, as would searching and updating it in future.</p>
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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