Hi all,
i need your experties where i now in trouble. How can i avoid data jump to next row if user enter "," even data actually in same field..in CSV the row saperate by ",".. so my CSV file is look not stabil when the data convert to wrong row or column.. Then I need to edit manually..
Here my script. This script work but come out with problem that i mention before.
How can i solve this issue?

<form name="export" action="req_reportCSV.php" method="post">
  <p><a href="req_report.php">Back</a> :: <a href="req_allTran.php">MIS Respond</a></p>
  <table width="1296" height="54" border="1" align="center">
    <tr bgcolor="#66CCCC">
      <td width="32" height="24">No</td>
      <td width="80">Mis Ref Id</td>
      <td width="141">Requestor</td>
      <td width="81">Request On </td>
      <td width="90">Category</td>
      <td width="48">Priority</td>
      <td width="122">Detail</td>
      <td width="126">Module (*for SAP)</td>
      <td width="126">Symptom</td>
      <td width="87">Approval</td>
      <td width="74">Status</td>
      <td width="119">PIC</td>
      <td width="88">Closing Date </td>
    </tr>

    <?php
                include 'connection/db_connect.php';
                $n=0;
                $csv_hdr = "Req ID, Mis Ref Id , Requestor, Request On, Category, Priority, Detail, Module, Symptom, Approval, Status, PIC, Closing Date";
                $sql="SELECT r.reqid, r.misRefId, r.date_req, r.request_by, r.category, r.priority, r.detail, r.modSAP, r.req_symptom, r.approval, r.curPIC,
                r.status, r.dateclose, c.cat_id, c.cat_name, u.empNo, u.name FROM request r, user u, category c WHERE r.request_by=u.empNo AND 
                r.category=c.cat_id ORDER BY r.reqid ASC";
                $result=mysql_query($sql) or die(mysql_error());
                while ($row=mysql_fetch_assoc($result)) {
                $n++;
    ?>
    <tr>
      <td><br>
      <?php echo $n;
      $csv_output .= $n.",";?></td>

      <td><a href="req_detail.php?reqid=<?php echo $row['reqid']; ?>"><br><?php echo $row['misRefId']; 
      $csv_output .= $row['misRefId'].", ";?><br /></a></td>

      <td><br><?php echo $row['name']; 
      $csv_output .= $row['name'].", ";?><br /></td>

      <td><br><?php echo $row['date_req']; 
      $csv_output .= $row['date_req'].", ";?><br /></td>

      <td><br><?php echo $row['cat_name']; 
      $csv_output .= $row['cat_name'].", ";?><br /></td>

      <td><br><?php echo $row['priority']; 
      $csv_output .= $row['priority'].", ";?><br /></td>

      <td><br><?php echo $row['detail']; 
      $csv_output .= $row['detail'].", ";?><br /></td>

      <td><br><?php echo $row['modSAP']; 
      $csv_output .= $row['modSAP'].", ";?><br /></td>

      <td><br><?php echo $row['req_symptom']; 
      $csv_output .= $row['req_symptom'].", ";?><br /></td>

      <td><br><?php echo $row['approval']; 
      $csv_output .= $row['approval'].", ";?><br /></td>

      <td><br><?php echo $row['status']; 
      $csv_output .= $row['status'].", ";?><br /></td>

      <td><br><?php echo $row['curPIC']; 
      $csv_output .= $row['curPIC'].", ";?><br /></td>

      <td><br><?php echo $row['dateclose']; 
      $csv_output .= $row['dateclose']. "\n";?><br /></td>
    </tr>
    <?php } ?>
  </table>
  <p>&nbsp;</p>


<input type="submit" value="Export to CSV">
    <input type="hidden" value="<?php echo $csv_hdr ?>" name="csv_hdr" id="csv_hdr">
    <input type="hidden" value="<?php echo $csv_output ?>" name="csv_output" id="csv_output">
    <a href="req_report.php">Back</a>
</form>

this is for converte file.

<?php
if (isset($_POST['csv_hdr'])) {
$out .= $_POST['csv_hdr'];
$out .= "\n";
}

if (isset($_POST['csv_output'])) {
$out .= $_POST['csv_output'];
}


$filename = $file."_".date("Y-m-d_H-i",time());

//Generate the CSV file header
header("Content-type: application/vnd.ms-excel");
header("Content-disposition: csv" . date("Y-m-d") . ".csv");
header("Content-disposition: filename=".$filename.".csv");

//Print the contents of out to the generated file.
print $out;

//Exit the script
exit;
?>

I have not tried this but I think text fields should be put within text delimiters (usualy double quotes). Try changing your code this way:

$csv_output .= '"$row['misRefId']"' . ", ";
...

This way commas will be within double quotes as part of the text and wont be treated as a field delimiter. Be careful if you have double quotes in text. In that case you have to escape them.

maybe i got too into it but try this, it will auto make the csv and table based on the fields pulled in the mysql query - not tested it btw:

<?php 
include 'connection/db_connect.php';
$n=0;
$sql="SELECT r.reqid, r.misRefId, r.date_req, r.request_by, r.category, r.priority, r.detail, r.modSAP, r.req_symptom, r.approval, r.curPIC,
r.status, r.dateclose, c.cat_id, c.cat_name, u.empNo, u.name FROM request r, user u, category c WHERE r.request_by=u.empNo AND 
            r.category=c.cat_id ORDER BY r.reqid ASC";
$result=mysql_query($sql) or die(mysql_error());
while ($row=mysql_fetch_assoc($result)) {
    if($n == 0){
        $htmlheaders = "<tr>\r\n";
        $htmldata = "<tr>\r\n";
        foreach($row as $k=>$v){
            $i = 0;
            if($i == 0){
                $i++;
                $headers = $k;
                $htmlheaders .= "<th>{$k}</th>\r\n";
                $data = '"'.str_replace('"',"'",$v).'"';
                $htmldata .= "<td>{$v}</td>\r\n";
            }else{
                $headers .= ",{$k}";
                $htmlheaders .= "<th>{$k}</th>\r\n";
                $data .= ',"'.str_replace('"',"'",$v).'"';
                $htmldata .= "<td>{$v}</td>\r\n";
            }
        }
        $headers .= "\r\n";
        $htmlheaders .= "</tr>\r\n";
        $data .= "\r\n";
        $htmldata .= "</tr>\r\n";
    }else{
        $htmldata .= "<tr>\r\n";
        foreach($row as $k=>$v){
            $i = 0;
            if($i == 0){
                $i++;
                $data .= '"'.str_replace('"',"'",$v).'"';
                $htmldata .= "<td>{$v}</td>\r\n";
            }else{
                $data .= ',"'.str_replace('"',"'",$v).'"';
                $htmldata .= "<td>{$v}</td>\r\n";
            }
        }
        $data .= "\r\n";
        $htmldata .= "</tr>\r\n";
    }
    $n++;
}
//$n == number of rows
echo $headers.$data;//csv
echo "<table>\r\n{$htmlheaders}{$htmldata}</table>";//html
?>

It's basically this that should fix it

<?php $csv_output .= '"'.str_replace('"',"'",$row['req_symptom']).'", ";?>

The csv needs the fields enclosed in double quotes, and in case the field has double quotes in it replace them to another character

Thanks all..
I have try your tips, but its nothing happen.. got same problem.. :(

Broj1, that qoute error..cannot put double qoute.. it show programming error..

There is another way of doing this. Instead of constructing a html and setting the headers you could open a csv file for writing:

$result=mysql_query($sql) or die(mysql_error());
$fp = fopen('file.csv', 'w');
// fetch row as numerical array
while ($row=mysql_fetch_row($result)) {
    // you can set field and text delimiters (3rd and 4th parameter)
    fputcsv($fp, $row,',','"');
}
fclose($fp);

Then you could provide a link to the user to open / download the csv file.

See http://php.net/manual/en/function.fputcsv.php.

Thanks all..
I have try your tips, but its nothing happen.. got same problem.. :(

sorry, i just tested it - i put the $i = 0; in the wrong place

while ($row=mysql_fetch_assoc($result)) {
    if($n == 0){
        $htmlheaders = "<tr>\r\n";
        $htmldata = "<tr>\r\n";
        $i = 0;
        foreach($row as $k=>$v){
            if($i == 0){
                $i++;
                $headers = $k;
                $htmlheaders .= "<th>{$k}</th>\r\n";
                $data = '"'.str_replace('"',"'",$v).'"';
                $htmldata .= "<td>{$v}</td>\r\n";
            }else{
                $headers .= ",{$k}";
                $htmlheaders .= "<th>{$k}</th>\r\n";
                $data .= ',"'.str_replace('"',"'",$v).'"';
                $htmldata .= "<td>{$v}</td>\r\n";
            }
        }
        $headers .= "\r\n";
        $htmlheaders .= "</tr>\r\n";
        $data .= "\r\n";
        $htmldata .= "</tr>\r\n";
    }else{
        $htmldata .= "<tr>\r\n";
        $i = 0;
        foreach($row as $k=>$v){
            if($i == 0){
                $i++;
                $data .= '"'.str_replace('"',"'",$v).'"';
                $htmldata .= "<td>{$v}</td>\r\n";
            }else{
                $data .= ',"'.str_replace('"',"'",$v).'"';
                $htmldata .= "<td>{$v}</td>\r\n";
            }
        }
        $data .= "\r\n";
        $htmldata .= "</tr>\r\n";
    }
    $n++;
}
//$n == number of rows
echo $headers.$data;//csv
echo "<table>\r\n{$htmlheaders}{$htmldata}</table>";//html
?>

Broj1, that qoute error..cannot put double qoute.. it show programming error..

What is the exact error message?

Broj1, that qoute error..cannot put double qoute.. it show programming error..

What is the exact error message?

probably this: $csv_output .= '"$row['misRefId']"' . ", ";

should be $csv_output .= '"'.$row['misRefId'].'", ';

or even $csv_output .= '"'.str_replace('"','&#34;',$row['misRefId']).'", ';

Thanks all... i try that code but still same when user enter "," or press Enter in text field. It will jump to next column press enter it jump to the next row. Same as my script above..got the same issue.. =(

If this has not been solved yet: can you post or upload:

  • the latest version of the main script with the table
  • the latest version of the req_reportCSV.php script
  • the output of the following SQL command (5 rows for testing):

    SELECT r.reqid, r.misRefId, r.date_req, r.request_by, r.category, r.priority, r.detail, r.modSAP, r.req_symptom, r.approval, r.curPIC, r.status, r.dateclose, c.cat_id, c.cat_name, u.empNo, u.name
    FROM request r, user u, category c
    WHERE r.request_by=u.empNo AND r.category=c.cat_id
    ORDER BY r.reqid ASC
    LIMIT 5

I can test this tonight. I did not test anything before because it is a lot of data to make up.

I think I found what is the problem. When you have text fields in csv they are supposed to be enclosed in double quotes and that is what Biiim and I were suggesting you. But when you add double quotes to text fields, the hidden input <inputname="csv_output"...> breaks since it also contains double quotes therefore the row is carried over incomplete through POST to the req_reportCSV.php file (in your browser have a look at source code for the main file - you will see errors). The solution is to use single quotes for input attributes like <inputname='csv_output'...> or to use single quotes for text delimiter in csv file.

The following is the code I tested on. Since I did not bother to set up a database I had to make up some test data which you can see in the beginning of the code. The last array (row) of the test data contains commas and it causes no errors.

Remove the test data and uncoment your code to deal with the database. You have to decide which fields are text fields and just surround them with $txt_delim. There are some comments within the code. I hope this will help you.

<?php
// some test data, delete this and read data from your database
$test_data = array(
        array(

        'reqid' => 'reqid1',
        'misRefId' => 'misRefId1',
        'name' => 'name1',
        'date_req' => 'date_req1',
        'cat_name' => 'cat_name1',
        'priority' => 'priority1',
        'detail' => 'detail1',
        'modSAP' => 'modSAP1',
        'req_symptom' => 'req_symptom1',
        'approval' => 'approval1',
        'status' => 'status1',
        'curPIC' => 'curPIC1',
        'dateclose' => 'dateclose1'),

        array(

        'reqid' => 'reqid2',
        'misRefId' => 'misRefId2',
        'name' => 'name2',
        'date_req' => 'date_req2',
        'cat_name' => 'cat_name2',
        'priority' => 'priority2',
        'detail' => 'detail2',
        'modSAP' => 'modSAP2',
        'req_symptom' => 'req_symptom2',
        'approval' => 'approval2',
        'status' => 'status2',
        'curPIC' => 'curPIC2',
        'dateclose' => 'dateclose2'),

        array(

        'reqid' => 'reqid3',
        'misRefId' => 'misRefId3',
        'name' => 'name3',
        'date_req' => 'date_req3',
        'cat_name' => 'cat_name3',
        'priority' => 'priority3',
        'detail' => 'detail3',
        'modSAP' => 'modSAP3',
        'req_symptom' => 'req_symptom3',
        'approval' => 'approval3',
        'status' => 'status3',
        'curPIC' => 'curPIC3',
        // this element contains commas
        'dateclose' => 'date,c,l,o,,s,,,e3'),
);
?>

<form name="export" action="req_reportCSV.php" method="post">
  <p><a href="req_report.php">Back</a> :: <a href="req_allTran.php">MIS Respond</a></p>
  <table width="1296" height="54" border="1" align="center">
    <tr bgcolor="#66CCCC">
      <td width="32" height="24">No</td>
      <td width="80">Mis Ref Id</td>
      <td width="141">Requestor</td>
      <td width="81">Request On </td>
      <td width="90">Category</td>
      <td width="48">Priority</td>
      <td width="122">Detail</td>
      <td width="126">Module (*for SAP)</td>
      <td width="126">Symptom</td>
      <td width="87">Approval</td>
      <td width="74">Status</td>
      <td width="119">PIC</td>
      <td width="88">Closing Date </td>
    </tr>

    <?php
    include 'connection/db_connect.php';

    // delimiter for text fields in a csv file is set to double quotes (")
    $txt_delim = '"';

    // initialize csv_output first
    $csv_output = '';

    $n=0;
    $csv_hdr  = 'Req ID,Mis Ref Id,Requestor,Request On,Category,Priority,';
    $csv_hdr .= 'Detail,Module,Symptom,Approval,Status,PIC,Closing Date';

    $sql="SELECT r.reqid, r.misRefId, r.date_req, r.request_by, r.category, r.priority, r.detail, r.modSAP, r.req_symptom, r.approval, r.curPIC,
                r.status, r.dateclose, c.cat_id, c.cat_name, u.empNo, u.name FROM request r, user u, category c WHERE r.request_by=u.empNo AND 
                r.category=c.cat_id ORDER BY r.reqid ASC";

    // uncomment this to work with the database
    // $result=mysql_query($sql) or die(mysql_error());
    // while ($row=mysql_fetch_assoc($result)) {

    // comment next row out since it was used only for testing
    foreach($test_data as $row) {
        $n++;
    ?>
    <!-- assemble teach html able row separately from the csv output -->
    <tr>
      <td><br>
      <?php echo $n;?></td>
      <td><a href="req_detail.php?reqid=<?php echo $row['reqid']; ?>"><br>
      <?php echo $row['misRefId'];?><br /></a></td>
      <td><br><?php echo $row['name'];?><br /></td>
      <td><br><?php echo $row['date_req'];?><br /></td>
      <td><br><?php echo $row['cat_name'];?><br /></td>
      <td><br><?php echo $row['priority'];?><br /></td>
      <td><br><?php echo $row['detail'];?><br /></td>
      <td><br><?php echo $row['modSAP'];?><br /></td>
      <td><br><?php echo $row['req_symptom'];?><br /></td>
      <td><br><?php echo $row['approval'];?><br /></td>
      <td><br><?php echo $row['status'];?><br /></td>
      <td><br><?php echo $row['curPIC'];?><br /></td>
      <td><br><?php echo $row['dateclose'];?><br /></td>
    </tr>

    <?php
        // assemble each row for csv output separately (easier to spot errors), 
        // note the curly braces arround array elements.
        // I do not think spaces after commas are OK, better avoid them
        $csv_output .= $n.",";
        $csv_output .= "{$row['misRefId']},";
        $csv_output .= "{$row['name']},";
        $csv_output .= "{$row['date_req']},";
        $csv_output .= "{$row['cat_name']},";
        $csv_output .= "{$row['priority']},";
        $csv_output .= "{$row['detail']},";
        $csv_output .= "{$row['modSAP']},";
        $csv_output .= "{$row['req_symptom']},";
        $csv_output .= "{$row['approval']},";
        $csv_output .= "{$row['status']},";
        $csv_output .= "{$row['curPIC']},";

        // this last row is an example of a text field enclosed with delimiters
        $csv_output .= "$txt_delim{$row['dateclose']}$txt_delim\n";
     } ?>
  </table>
  <p> <?php echo "<pre>$csv_output</pre>"; ?> </p>

<input type="submit" value="Export to CSV">
    <input type="hidden" value="<?php echo $csv_hdr ?>" name="csv_hdr" id="csv_hdr" />

    <!-- The following input element uses single quotes for the value attibute 
    (the value in $csv_output itself contains double quotes) -->
    <input type="hidden" value='<?php echo $csv_output ?>' name="csv_output" id="csv_output" />

    <a href="req_report.php">Back</a>
</form>

Another thing: in the req_reportCSV.php file you have to set the default timezone otherwise you will get warnings (which might be saved in your csv file). You can set the default timezone in php.ini using date.timezone directive:

date.timezone = "Europe/Amsterdam"

or temporary in the script using date_default_timezone_set() function:

date_default_timezone_set('Europe/Amsterdam');

This will save you trouble either now or in future (depending on PHP version you use).

See http://www.php.net/manual/en/datetime.configuration.php#ini.date.timezone
and http://www.php.net/manual/en/function.date-default-timezone-set.php.

Thanks all... i try that code but still same when user enter "," or press Enter in text field. It will jump to next column press enter it jump to the next row. Same as my script above..got the same issue.. =(

Your problem isn't writing a csv format file it's your script not working properly?

As far as I understand a user is entering data in a form and this data gets written to a CSV file. If there is comma (,) in entered text, the CSV file gets broken if it is not delimited. If you use double quotes as a delimiter this breaks when saved to a hidden input field which also uses double quotes for a value attribute. But it is hard to tell since no enough information has been given. That is why I asked HasNor in earlier post to upload the latest versions.

Hi all, sorry for silent last 2 week..i quick bz before.Regarding to your suggestion, I have tried it and thats work as per wish..
For comma issue it not happen as before. Thank a lot all of you.
But if user enter to the next line in text field (in system), it will jump to the next row (in CVS file)..

Please,help me...

This is my latest script. I only update this file..

report_exp.php

<form name="export" action="req_reportCSV.php" method="post">
 <p><a href="req_report.php">Back</a> :: <a href="req_allTran.php">MIS Respond</a></p><table width="1296" height="54" border="1" align="center">
   <tr bgcolor="#66CCCC">
       <td width="32" height="24">No</td>
       <td width="80">Mis Ref Id</td>
       <td width="141">Requestor</td>
       <td width="81">Request On </td>
       <td width="90">Category</td>
       <td width="48">Priority</td>
       <td width="122">Detail</td>
       <td width="126">Module (*for SAP)</td>
       <td width="126">Symptom</td>
       <td width="87">Approval</td>
       <td width="74">Status</td>
       <td width="119">PIC</td>
       <td width="88">Closing Date </td>
    </tr>
         <?php
          include 'connection/db_connect.php';
          // delimiter for text fields in a csv file is set to double quotes (")
             $txt_delim = '"';
            // initialize csv_output first
            $csv_output = '';
            $n=0;
            $csv_hdr  = 'Req ID,Mis Ref Id,Requestor,Request On,Category,Priority,';
            $csv_hdr .= 'Detail,Module,Symptom,Approval,Status,PIC,Closing Date';
            $sql="SELECT r.reqid, r.misRefId, r.date_req, r.request_by, r.category, r.priority, r.detail, r.modSAP, r.req_symptom, r.approval, r.curPIC,
                 r.status, r.dateclose, c.cat_id, c.cat_name, u.empNo, u.name FROM request r, user u, category c WHERE r.request_by=u.empNo AND 
                 r.category=c.cat_id ORDER BY r.reqid ASC";
            // uncomment this to work with the database
             $result=mysql_query($sql) or die(mysql_error());
             while ($row=mysql_fetch_assoc($result)) {  
            // comment next row out since it was used only for testing
               // foreach($test_data as $row) {
                 $n++;
         ?>
   <!-- assemble teach html able row separately from the csv output -->
             <tr>
              <td><br>
              <?php echo $n;?></td>
              <td><a href="req_detail.php?reqid=<?php echo $row['reqid']; ?>"><br>
               <?php echo $row['misRefId'];?><br /></a></td>
               <td><br><?php echo $row['name'];?><br /></td>
               <td><br><?php echo $row['date_req'];?><br /></td>
               <td><br><?php echo $row['cat_name'];?><br /></td>
               <td><br><?php echo $row['priority'];?><br /></td>
               <td><br><?php echo $row['detail'];?><br /></td>
               <td><br><?php echo $row['modSAP'];?><br /></td>
               <td><br><?php echo $row['req_symptom'];?><br /></td>
               <td><br><?php echo $row['approval'];?><br /></td>
               <td><br><?php echo $row['status'];?><br /></td>
               <td><br><?php echo $row['curPIC'];?><br /></td>
               <td><br><?php echo $row['dateclose'];?><br /></td>
             </tr>
                                                                                                                                                                                                       <?php
                    // assemble each row for csv output separately (easier to spot errors), 
                    // note the curly braces arround array elements.
                    // I do not think spaces after commas are OK, better avoid them
                           $csv_output .= $n.",";
                           $csv_output .= "{$row['misRefId']},";
                           $csv_output .= "{$row['name']},";
                           $csv_output .= "{$row['date_req']},";
                           $csv_output .= "{$row['cat_name']},";
                           $csv_output .= "{$row['priority']},";
                           $csv_output .= "{$row['detail']},";
                           $csv_output .= "{$row['modSAP']},";
                           $csv_output .= "{$row['req_symptom']},";
                           $csv_output .= "{$row['approval']},";
                           $csv_output .= "{$row['status']},";
                           $csv_output .= "{$row['curPIC']},";
                           // this last row is an example of a text field enclosed with delimiters
                           $csv_output .= "$txt_delim{$row['dateclose']}$txt_delim\n";
                           } ?>
                                                                                                                                                                                                     </table>
                 <p> <?php //echo "<pre>$csv_output</pre>"; ?> </p>
                  <input type="submit" value="Export to CSV">
                  <input type="hidden" value="<?php echo $csv_hdr ?>" name="csv_hdr" id="csv_hdr" />
                   <!-- The following input element uses single quotes for the value attibute 
                   (the value in $csv_output itself contains double quotes) -->
                  <input type="hidden" value='<?php echo $csv_output ?>' name="csv_output" id="csv_output" />
                    <a href="req_report.php">Back</a>
                </form>

sorry!! hurm... that's ok if user enter this " ; " but if user enter " , " it will jump to next column and if user press enter to next line it will jump to next row after convert to CSV file.. =(

what should i do actually??

$csv_output .= $n.",";
                           $csv_output .= "{$row['misRefId']},";
                           $csv_output .= "{$row['name']},";
                           $csv_output .= "{$row['date_req']},";
                           $csv_output .= "{$row['cat_name']},";
                           $csv_output .= "{$row['priority']},";
                           $csv_output .= "{$row['detail']},";
                           $csv_output .= "{$row['modSAP']},";
                           $csv_output .= "{$row['req_symptom']},";
                           $csv_output .= "{$row['approval']},";
                           $csv_output .= "{$row['status']},";
                           $csv_output .= "{$row['curPIC']},";
                           // this last row is an example of a text field enclosed with delimiters
                           $csv_output .= "$txt_delim{$row['dateclose']}$txt_delim\n";

put the text fields in quotes?

$txt_delim = '"';

The delimiter is what separates fields eg. the comma quotes is what encloses the field

$delim = ',';
$enclosed = '"';
$EOL = "\r\n";//end of line

$csv_output .= $enclosed . $n . $enclosed . $delim;
$csv_output .= $enclosed . $row['misRefId'] . $enclosed . $delim;
$csv_output .= $enclosed . $row['name'] . $enclosed . $delim;
$csv_output .= $enclosed . $row['date_req'] . $enclosed . $delim;
$csv_output .= $enclosed . $row['cat_name'] . $enclosed . $delim;
$csv_output .= $enclosed . $row['priority'] . $enclosed . $delim;
$csv_output .= $enclosed . $row['detail'] . $enclosed . $delim;
$csv_output .= $enclosed . $row['modSAP'] . $enclosed . $delim;
$csv_output .= $enclosed . $row['req_symptom'] . $enclosed . $delim;
$csv_output .= $enclosed . $row['approval'] . $enclosed . $delim;
$csv_output .= $enclosed . $row['status'] . $enclosed . $delim;
$csv_output .= $enclosed . $row['curPIC'] . $enclosed . $delim;
// this last row is an example of a text field enclosed with delimiters
//last field, no trailing comma
$csv_output .= $enclosed . $row['dateclose'] . $enclosed . $EOL;

It's a little hard to understand what you're asking

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.