Welcome Guest, Not a member yet? Register   Sign In
how to access the count?
#11

(This post was last modified: 08-20-2018, 06:23 PM by richb201.)

Tx rocs. But no, I didn't use count. I just needed to access the existing field. I am having an additional issue. I thought the problem was that I didn't know how many items were in the array. I am using fputcsv and writing out the fields. But whenever I look in the file, it contains a lot more data. Seems like a lot of junk text is getting in the csv file besides the fields I am writing, after the data is all output. Here is the code. Do you see something obvious?

$output = fopen("php://output","w") or die("Can't open php://output");
header("Content-Type:application/csv");
header("Content-Disposition:attachment;filename=substantiator_contemporaneous.csv");

       
 foreach ($result['Items'] as $data) {
     $i++;
     fputcsv($output, array(
        $marshaler->unmarshalValue($data['campaign']),
        $marshaler->unmarshalValue($data['activity_date']),
        $marshaler->unmarshalValue($data['business_comp']),
       $marshaler->unmarshalValue($data['project']),
       $marshaler->unmarshalValue($data['activity']),
       $marshaler->unmarshalValue($data['email']),
        $marshaler->unmarshalValue($data['hours'])),
        $delimiter=",",
        $enclosure='"');
     if($i==$iCount)
         break;
                                     }
 fclose($output) or die("Can't close php://output");
//  force_download('substantiator_contemporaneous.csv');


I think part of the problem is that $output is used by Grocery Crud which is sticking part of the HTML into the end of the $output. I tried changing the php://output to output_csv, but that didn't work. 
proof that an old dog can learn new tricks
Reply
#12

The output starts fine for the first 13 lines. Then it appends html to the file. Could it be because the fopen is fopen("php://output","w") and Grocery Crud uses $output? Is there someway to flush the output buffer before I use it?

campaign activity_date business_comp project activity email hours
Apple Mon Aug 13 2018 IOS Make WORD easier to architectural design [email protected] 4
Apple Mon Aug 13 2018 Mac Make WORD easier to acceptance testing [email protected] 4
Apple Mon Aug 13 2018 IOS secure logins acceptance testing [email protected] 4
Apple Mon Aug 13 2018 Mac Make WORD easier to acceptance testing [email protected] 4
Apple Mon Aug 13 2018 IOS Make WORD easier to acceptance testing [email protected] 4
Apple Mon Aug 13 2018 IOS Make WORD easier to acceptance testing [email protected] 4
Apple Mon Aug 13 2018 IOS Make WORD easier to acceptance testing [email protected] 4
Apple Mon Aug 13 2018 Mac Make WORD easier to architectural design [email protected] 4
Apple Mon Aug 13 2018 Mac speed up loading acceptance testing [email protected] 4
Apple Mon Aug 13 2018 IOS secure logins architectural design [email protected] 4
Apple Mon Aug 13 2018 Mac secure logins architectural design [email protected] 4
Apple Mon Aug 13 2018 IOS Make WORD easier to architectural design [email protected] 4
<html lang="en">
"<br><br><br><br><br><br><h3>ACTIVE CAMPAIGN: Apple</h3> <head>"
" <title></title>"
" <meta name=""resource-type"" content=""document"" />"
" <meta name=""robots"" content=""all" index follow"/>
" <meta name=""googlebot"" content=""all" index follow" />
" "
" <meta name=""keywords"" content="""" />"
" <meta name=""description"" content="""" />"

" "
" "
" <script src=""http://localhost/assets/themes/default/js/jquery-1.9.1.min.js""></script>"
" <script src=""http://localhost/assets/themes/default/hero_files/bootstrap-transition.js""></script>"
" <script src=""http://localhost/assets/themes/default/hero_files/bootstrap-collapse.js""></script>"
" <script src=""http://localhost/js/jquery.orgchart.js""></script>"
" <script src=""http://localhost/js/javascript_funcs.js""></script>"
" "
<!-- Le styles -->

<link href="http://localhost/assets/themes/default/hero_files/bootstrap.css" rel="stylesheet">
<link href="http://localhost/assets/themes/default/hero_files/bootstrap-responsive.css" rel="stylesheet">
<link href="http://localhost/assets/themes/default/css/general.css" rel="stylesheet">
<link href="http://localhost/assets/themes/default/css/custom.css" rel="stylesheet">
<link href="http://localhost/assets/css/jquery.orgchart.css" rel="stylesheet">

<!-- Le HTML5 shim for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->

<!-- Le fav and touch icons -->
<link rel="shortcut icon" href="http://localhost/assets/themes/default/images/favicon.png" type="image/x-icon"/>
" <meta property=""og:image"" content=""http://localhost/assets/themes/default/images/facebook-thumb.png""/>"
" <link rel=""image_src"" href=""http://localhost/assets/themes/default/images/facebook-thumb.png"" />"
" <style type=""text/css"">"

" :Confusedelection{ background-color: #E13300; color: white; }"
" ::moz-selection{ background-color: #E13300; color: white; }"
" ::webkit-selection{ background-color: #E13300; color: white; }"

" body {"
" background-color: #fff;"
" margin: 40px;"
" font: 13px/20px normal Helvetica" Arial sans-serif;
proof that an old dog can learn new tricks
Reply
#13

Figured it out from here, if anyone has the same issue.

https://stackoverflow.com/questions/1199...a-csv-file
proof that an old dog can learn new tricks
Reply
#14

What API is this?
Reply




Theme © iAndrew 2016 - Forum software by © MyBB