You are here:  » merchant csv export


merchant csv export

Submitted by philstone on Thu, 2006-11-02 16:58 in

Hi Dave

Was wondering would there be a way to create a csv file automatically that is an output of your merchants data after filters have been applied?

Regards

phil

Submitted by support on Thu, 2006-11-02 17:03

Hi Phil,

This has come up before - there's some code for exporting the entire product database as csv in this thread:

http://www.pricetapestry.com/node/506

Use the version from the very last message. If you only want a specific merchant, you'd have to change the SQL, something like this:

<?php
  
require("includes/common.php");
  function 
csvsafe($text)
  {
    return 
str_replace(array("\n","\r",",")," ",$text);
  }
  
header("Content-Type: application/octet-stream");
  
header("Content-Disposition: attachment; filename=products.csv");
  
$sql "SELECT * FROM `".$config_databaseTablePrefix."products` WHERE merchant='MerchantName'";
  print 
"Merchant,Name,Description,ImageURL,BuyURL,Price,Category,Brand\n";
  
$link mysql_connect($config_databaseServer,$config_databaseUsername,$config_databasePassword);
  
mysql_select_db($config_databaseName,$link);
  
$result mysql_unbuffered_query($sql,$link);
  while(
$row mysql_fetch_array($result,MYSQL_ASSOC))
  {
    print 
csvsafe($row["merchant"]).",";
    print 
csvsafe($row["name"]).",";
    print 
csvsafe($row["description"]).",";
    print 
csvsafe($row["image_url"]).",";
    print 
csvsafe($row["buy_url"]).",";
    print 
csvsafe($row["price"]).",";
    print 
csvsafe($row["category"]).",";
    print 
csvsafe($row["brand"])."\n";
  }
?>

(the only change is adding the WHERE clause to the SQL on line 6)

Cheers,
David.