I think what you are trying to so is probably impossible. How could you ever know what commas are delimiters and what aren't?
Hi.
I'm writing a script to import a vendor's datafeed from AffiliateWindow into a MySQL db so I can then show the products on my website.
I admit I'm no PHP expert, but I've been trying to break the CSV file into parts using the 'explode' function. This was working fine with some small CSV test files I had produced, but when I tried it on the actual vendor datafeed the data was imported incorrectly.
After a couple of minutes scratching my head, I noticed that some of the description fields in the datafeed were very lengthy and actually contained commas within the description. The explode function was therefore seeing each comma as a delimiter (as it should), but I don't want to break up the description because it should be completely in a field of it's own.
Does that make sense? I'd appreciate some advice on how to get over this hurdle. As I say, I'm only a novice when it comes to PHP so the answer may well be obvious, but I'll take the flak and any comments about being 'stoopid' if only someone could help me.
thanks in advance.
Nick
I think what you are trying to so is probably impossible. How could you ever know what commas are delimiters and what aren't?
can u get the feed in another format aside from .csv?
how about tab seperated or pipe?
that would solve your dilemma.
Affiliate Citizen
Holiday Reviews & Travel Deals || Travel Merchants: Please contact me if you have special offers or codes
If you have PHP 5, the easiest way to parse Affiliate Window feeds is to download the feed as XML. You can then use the simple PHP extension which makes parsing the file really easy!
EG:
The above code will print out some fields for each product in the XML file. You can easily update it to update or insert into the database.PHP Code:<?php
$xml = simplexml_load_file("/home/user_dir/public_html/test/awProductFeed.xml");
foreach($xml->merch->prod as $product){
echo "Name: " . $product->name . "<br>";
echo "AW Cat ID: " . $product->cat->awCatId . "<br>";
echo "Brand: " . $product->brand . "<br>";
echo "AW Link: " . $product->awLink . "<br>";
echo "Delivery Cost: " . $product->delCost . "<br>";
echo "Price: " . $product->price->search . "<br>";
echo "--------------------------" . "<br>";
}
?>
ah sorry i just noticed you are using affiliatewindow.
they supply feeds in different formats. Use either a pipe separated one and explode by the '|' character or use a tab seperated one and explode by ' \t '.
Easy! Hope that solves that problem.
Dave![]()
Affiliate Citizen
Holiday Reviews & Travel Deals || Travel Merchants: Please contact me if you have special offers or codes
or switch from explode to fget csv - PHP: fgetcsv - Manual
Dan Morley
alpharooms.com
daniel at alpharooms dot com - Hotels, Flights, Airport Transfers, Care Hire + More! sign up
My Blog | Cheap Holidays
Nick
You can also populate your datafeed table using the LOAD DATA statement. This is very fast at loading data.
I use the data feeds delimited by Tab not comma.
The following extract uses Affiliate window's 1.2 data format that has lots of extra (usually empty) fields
GerryCode:LOAD DATA LOCAL INFILE 'C:/data/files/aw/datafeed.txt' INTO TABLE aw_feeds FIELDS TERMINATED BY '\t' optionally enclosed by '"' LINES TERMINATED BY '\n' IGNORE 1 LINES (`merchant_id`,`merchant_name`,`aw_product_id`,`product_id`, `upc`,`ean`,`mpn`,`isbn`,`model_number`,`product_name`, `description`,`specifications`,`promotional_text`, `merchant_category`,`category_id`,`category_name`, `language`,`brand_name`,`deep_link`,`thumb_url`,`image_url`, `aw_deep_link`,`aw_thumb_url`,`aw_image_url`,`delivery_time`, `valid_from`,`valid_to`,`currency`,`search_price`,`store_price`, `rrp_price`,`display_price`,`delivery_cost`,`web_offer`,`pre_order`, `in_stock`,`stock_quantity`,`is_for_sale`,`warranty`,`condition`, `product_type`,`parent_product_id`,`commission_group`,`type`);
Wow! Thanks to everyone who replied, and so quickly!
Looks like I have a few options to try out. I'll see how I get on and post back once I've done it.
Thanks again to everyone. I'm new to this forum, but it's already one of the most helpful I've found.
just seen this, if it's AffiliateWindow you're using then use the API that AW provides. http://www.affiliatewindow.com/affil...ervice_api.pdf that is what i'm using, and i can import the results directly into a table on my MySQL database
Generally, if you're using files which have the delimiter in the actual fields, (e.g. a comma in this case) those fields should have quotes round them so they can be ignored.
<plug>
The Affilistore tutorial I'm doing uses a file delimited with semicolons, and you'll see there are also semicolons in the product titles. The file importer in Affilistore knows to ignore these as there are quote marks round the whole product field.
Check it out here
</p>
This can still allow cock-ups, particularly in postal address data where you can get stuff like "Dunworkin", 2 The Street all in one field and the poor importer doesn't know whether it's coming or going. Thank god I stopped working in direct mail 8 years ago!
For flat files, I usually find that tab delimited is most reliable and easiest to handle as it's not possible to type a tab into an online form.
Subject: Building an Affiliate Store Was Never so Easy!
If you ever thought building an affiliate store was just too hard then the patented Datafeedr "Click & Create" system is just what you've been waiting for!
Build Unlimited Affiliate Datafeed eCommerce Stores | datafeedr.com
Hi Nick,
We had recently built a product catalog / affiliate store website. We had faced the same problem. Try to get the xml feeds if possible or get the pipe seperated csv feeds.
This is website that we have built www.buy-products-online.co.uk
If you have any problems then do let me know and I will see what I can do for you
Cheers,
Nick
Nick
WEBWORX | Web Desgin & Development, SEO, Content Writing | www.webworxindia.com
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks