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
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.
©2006-2025 IAAI Software | Contact Us | Privacy Policy
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.