Hi David,
I use Magic Parser to store product feeds in a database.
What I want to do now is to check if every field that I want to import still exists, before importing the feed. Reason for this is that the feed providers add and remove fields from time to time.
Can this be done?
//Jasper
Thanks for your reply David.
I think, however, that my question wasn't clear. Basically I want to check if the feed is still valid, before importing the data.
Let's say I have a feed with 3 fields: name, price and manufacturer. This feed will be imported to the database.
Suddenly the feed supplier removes the field 'price' form his feed. This makes the feed information useless, so I don't want to import it but I want a notification by e-mail.
I hope the above makes sense...
//Jasper
Hi Jasper,
Sure - in that case it should just be a case of checking for all fields before inserting, and return-ing from myRecordHandler if they're not all valid; for example:
function myRecordHandler($record)
{
if (!$record["name"] || !$record["price"] || !$record["manufacturer"]) return;
// rest of code follows to INSERT new record...
}
Hope this helps!
Cheers,
David.
That helps a lot! Thanks again David for your great support!
Hi Jasper,
Sure - it's basically just a case of running a query to SELECT the product beforehand, and then only INSERTing if there are no results, for example:
function myRecordHandler($record)
{
// query database and return from myRecordHandler if product already exists
$sql = "SELECT * FROM products WHERE name='".mysql_escape_string($record["NAME"])."'";
if (mysql_num_rows(mysql_query($sql)) return;
// rest of code follows to INSERT new record...
}
Hope this helps!
Cheers,
David.