Jump to content

Recommended Posts

<?php

$fh = fopen('include/temp/temp.csv', "w") or die("PROBLEM!");

// Create a header row in the file
fwrite($fh, "Source,Called,Destination,Ani,Call Time\n") or die("WE GOT A PROBLEM WRITING!");

// Loop through the results, writing to the file
while ($row = mysql_fetch_assoc($UserRated1)){
$data = $row['Originating_TG'] . "," . $row['Inpulsed_Digits'] . "," . $row['IB_Region_Name'] . "," . $row['ANI'] . "," . $row['UTCTime'] . "\n";
fwrite($fh, $data);
}
// Close the file
fclose($fh);

// Compress a file
compress("include/temp/temp.csv", "include/temp/temp.csv.gz");
echo "<a href=\"include/temp/temp.csv.gz\">Download link </a><br />";
?>

 

 

All the links are just temporary till I get a finished product and I can get a temp file script.

What does the query look like that you're using to pull the data from the database? If you are just pulling the fields you are writing, you can using implode() to put the commas between the fields. Also storing all the data in temporary array and then doing one write might be faster:

<?php
$data = array();
while ($row = mysql_fetch_array($UserRated1)){
$data[] = implode(',',$row);
}
fwrite($fh, implode("\n",$data);
?>

 

I don't know if it's more efficient or not, but you're doing only one write instead of many.

 

Ken

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.