Jump to content

Recommended Posts

I created the csv file, but it only shows the last record in my db.  How can I make it show all of the records?  Here's the code:

 

<?php
include 'connect.php';
$que = mysql_query("SELECT * FROM `CP`");
while($row = mysql_fetch_assoc($que)){
$bfn = $row['bfn'];
$bln = $row['bln'];
$bssn = $row['bssn'];
$bdob = $row['bdob'];
$bemp = $row['bemp'];
$bjt = $row['bjt'];
$cjten = $row['cjten'];
$bjmi = $row['bjmi'];
$bjten = $row['bjten'];
$bb1 = $row['bb1'];
$bb1a = $row['bb1a'];
$bb = $row['bb2'];
$bb2a = $row['bb2a'];
$bb3 = $row['bb3'];
$bb3a = $row['bb3a'];
$cfn = $row['cfn'];
$cln = $row['cln'];
$cdob = $row['cdob'];
$cssn = $row['cssn'];
$cemp = $row['cemp'];
$cjt = $row['cjt'];
$cb1 = $row['cb1'];
$cb1a = $row['cb1a'];
$cb2 = $row['cb2'];
$cb2a = $row['cb2a'];
$cb3 = $row['cb3'];
$cb3a = $row['cb3a'];
$addy = $row['addy'];
$zip = $row['zip'];
$taxes = $row['taxes'];
$ins = $row['ins'];
$tenure = $row['tenure'];
$value = $row['value'];
}
$data = "";
$row = $bfn.",";
$row .= $bln.",";
$row .= $bssn.",";
$data .= $row."\n";

header("Content-type: application/x-msdownload");
header("Content-Disposition: attachment; filename=log.csv");
header("Pragma: no-cache");
header("Expires: 0");
echo $data;
?>

Link to comment
https://forums.phpfreaks.com/topic/66544-solved-csv-exporting/
Share on other sites

You would do it the same way, it's just that at the moment every time you read a record you are overwriting the previous values, so you are just left with the last record's values. You need to write the record within the loop.

 

But why retrieve the whole row when you only need 3 cols?

 

<?php
include 'connect.php';
header("Content-type: application/x-msdownload");
header("Content-Disposition: attachment; filename=log.csv");
header("Pragma: no-cache");
header("Expires: 0");

$sql = "SELECT bfn,bln,bssn FROM `CP`";
$que = mysql_query($sql);
while ($row = mysql_fetch_row($que)) {
    $data = join (',', $row) . "\n";
    echo $data;
}
?>

Link to comment
https://forums.phpfreaks.com/topic/66544-solved-csv-exporting/#findComment-333284
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.