bluesoul Posted January 12, 2009 Share Posted January 12, 2009 Ugh, having some problems getting this working. Before my loop: $list = array ( 'Account ID,Invoice ID,Domain,Invoice Date, Registrar, Description, Exp. Date, Charge, Balance'); In the loop: $fp = fopen('invoice'.$timestamp.'.csv', 'w'); $list .= array ( "$aaid,$aiid,$adn,$invdate, $arid, $adesc, $expdate, $charge, $balance"); foreach ($list as $line) { fputcsv($fp, split(',', $line)); } After the loop: fclose($fp); Results in "Warning: Invalid argument supplied for foreach() in searchinvoices.php on line 77". I'm assuming it's because I can only pass it one element at a time. Ideas? Link to comment https://forums.phpfreaks.com/topic/140535-solved-generating-a-csv-on-the-fly/ Share on other sites More sharing options...
kenrbnsn Posted January 12, 2009 Share Posted January 12, 2009 You do not want to use the "." operator, try something like this: <?php $list = array(); $list[] = array ( 'Account ID,Invoice ID,Domain,Invoice Date, Registrar, Description, Exp. Date, Charge, Balance'); $fp = fopen('invoice'.$timestamp.'.csv', 'w'); $list[] = array ( "$aaid,$aiid,$adn,$invdate, $arid, $adesc, $expdate, $charge, $balance"); foreach ($list as $line) { fputcsv($fp, split(',', $line)); }?> Ken Link to comment https://forums.phpfreaks.com/topic/140535-solved-generating-a-csv-on-the-fly/#findComment-735428 Share on other sites More sharing options...
Mchl Posted January 12, 2009 Share Posted January 12, 2009 $fp = fopen('invoice'.$timestamp.'.csv', 'w'); $list = array ( 'Account ID','Invoice ID','Domain','Invoice Date','Registrar','Description','Exp. Date','Charge','Balance'); fputcsv($fp,$list); $list = array ( $aaid,$aiid,$adn,$invdate,$arid,$adesc,$expdate,$charge,$balance); fputcsv($fp,$list); Link to comment https://forums.phpfreaks.com/topic/140535-solved-generating-a-csv-on-the-fly/#findComment-735430 Share on other sites More sharing options...
rhodesa Posted January 12, 2009 Share Posted January 12, 2009 couple of things... -the fopen should probably be OUTSIDE the loop -you are putting variables into a string then back to an array...just put them right into the array: $list = array ($aaid,$aiid,$adn,$invdate, $arid, $adesc, $expdate, $charge, $balance); fputcsv($fp, $list); Link to comment https://forums.phpfreaks.com/topic/140535-solved-generating-a-csv-on-the-fly/#findComment-735432 Share on other sites More sharing options...
bluesoul Posted January 12, 2009 Author Share Posted January 12, 2009 $fp = fopen('invoice'.$timestamp.'.csv', 'w'); $list = array ( 'Account ID','Invoice ID','Domain','Invoice Date','Registrar','Description','Exp. Date','Charge','Balance'); fputcsv($fp,$list); $list = array ( $aaid,$aiid,$adn,$invdate,$arid,$adesc,$expdate,$charge,$balance); fputcsv($fp,$list); This got it, thanks a ton, I'd have been beating my head on this for a while. Link to comment https://forums.phpfreaks.com/topic/140535-solved-generating-a-csv-on-the-fly/#findComment-735434 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.