Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

Saving an array to a csv file

$
0
0

I'm haveing a heck of a time trying to figure this out.

 

All I want to do is save a SELECT array (mysql) to a CSV file.

 

Here's what I'm trying. It

$result = "SELECT product.reference AS sku, product.price - specific_price.reduction AS price, stock_available.quantity, marketplace_product_option.asin1 AS 'product-id', 'ASIN' AS 'product-id-type', product.condition AS 'condition-type'
FROM product, specific_price, stock_available, marketplace_product_option
WHERE product.id_product = specific_price.id_product
AND product.id_product = stock_available.id_product
AND product.id_product = marketplace_product_option.id_product;";

$fp = fopen('/home/aonewebs/public_html/amazon-export.csv', 'w+');
if ($fp && $result) 
{     
       while ($row = mysql_fetch_row($result)) 
       {
          fputcsv($fp, array_values($row)); 
       } 
}

creates an empty file (even though therer are 3000 lines to that array.

 

I'm sure I'm missing something obvious.

 

Any and all help greatly appreciated.

 

Ron


Viewing all articles
Browse latest Browse all 13200

Trending Articles