lakshmi lakshmi - 2 years ago 84
PHP Question

How to generate the CSV and PDF selecting two dates json value in Drupal7

drupal_add_http_header('Content-Type', 'text/csv');
// code indentation
$fp = fopen('php://transactions', 'w')
foreach ($result->response as $transaction) {
fputcsv($fp, $transaction);

The (result->response as transaction) contains all the data, with that only i arrange in table format to view for the customer. This same data i am selecting (from and to->date result) to be download in CSV.

Print of transaction:
In stdClassObject([card]=>1234,[fromdate]=>4/1/2016,[amount]=>5000)

Suggestion Needed.

Answer Source

Instead of

fputcsv($fp, $transaction);


fputcsv($fp, array($transaction->card, $transaction->fromdate, $transaction->amount));

for formatting the numbers you can use as below:

$number = (float) str_replace( ',', '', '5,000.00');
echo number_format($number, '2','.', '');


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download