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? Quote Link to comment 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 Quote Link to comment 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); Quote Link to comment 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); Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.