Jump to content

Saving CSV file


rseigel
Go to solution Solved by rseigel,

Recommended Posts

I'm trying to get this code to save a csv file to the root of my hosting accont.

$result = mysql_query("SELECT p.reference AS sku, IFNULL( p.price - sp.reduction, p.price ) AS price, sa.quantity, mpo.asin1 AS 'product-id', 'ASIN' AS 'product-id-type', p.condition AS 'condition-type'
FROM product p
LEFT JOIN specific_price sp
USING ( id_product )
JOIN stock_available sa
USING ( id_product )
JOIN marketplace_product_option mpo
USING ( id_product )
WHERE mpo.asin1 > ''"); 
if (!$result) die('Couldn\'t fetch records'); 
$num_fields = mysql_num_fields($result); 
$headers = array(); 
for ($i = 0; $i < $num_fields; $i++) 
{     
       $headers[] = mysql_field_name($result , $i); 
} 
$csv_filename = "export-amazon.csv";
$fp = fopen($csv_filename, 'w+');


if ($fp && $result) 
{
    fputcsv($fp, $headers);
    while ($row = mysql_fetch_row($result)) 
    {
        fputcsv($fp, array_values($row)); 
    }
}

I've been digging and digging on the internet and nothing seems to work.

 

In the above code, I know for a fact that the SELECT works perfectly. It just doesn't save a file.

 

Any ideas, thoughts, anything?? O_o

 

Thanks,Ron

Edited by rseigel
Link to comment
Share on other sites

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.