You are here:  » Creating an XML feed for sub-affiliates to use

Support Forum



Creating an XML feed for sub-affiliates to use

Submitted by sbedigital on Sat, 2007-12-29 20:40 in

Hi there,

Running your script for few days and looks excellent. See http://www.bestbuyers.co.uk.
While applying the finishing touches, I have stumbled on a problem raised by one of my affliate. I want to create a php script that outputs search queries in xml format similar to PPC XML Feed you get.

For example, if affilite want get 10 results from my database he should point his application http://www.domain.com/feeds.php?listing=10&format=xml

And obviously, FEEDS.PHP is php applicating that generates the XML feed, LISTING is number of listing to present to affiliate's request and FORMAT is to structure the feed in either XML, CSV, or RSS

.. And XML structure should be as follows:

<count>Total Results Found</count>
<item>Item Name</item>
<desc>Item Description</desc>
<pict>URL to item picture</picts>
<merchant>Seller's Name</merchant>
<redirect>Redirect URL</redirect>

... CSV and RSS to stuructred in similar lines.

Any HELP????

Submitted by support on Sun, 2007-12-30 15:20

Hi,

A good format in which to produce your feed is RSS - and there is code to do exactly that in the following thread:

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

(scroll down for the version that produces results based on a query)

Cheers,
David.

Submitted by sbedigital on Tue, 2008-01-01 21:34

Thnaks for quick response.

Ok I get the XML feed I needed but there is simple item missing. How do get the script to make xml file on the fly, as rather than making a "xyz.xml" file for download, I need this to make xml file on the fly and listing limitation supplied by the affiliates themselves for example:

when they call feed.php?q=ipod&ln=10 it should disply 10 listings with keyword IPOD. The TAG "ln" (LN stands for Listing Number) controls how many product they want to disply.

Submitted by support on Wed, 2008-01-02 11:16

Hi,

The download is only forced by the following line:

  header("Content-Disposition: attachment; filename=products.xml");

Here's a version without that line, and with an extra parameter "ln" to limit the number of results:

feed.php

<?php
  require("includes/common.php");
  header("Content-Type: text/xml");
  print "<?xml version='1.0' encoding='UTF-8'?>";
  print "<rss>";
  print "<channel>";
  $q = $_GET["q"];
  $ln = intval($_GET["ln"]);
  if (strlen($q) > 3)
  {
    $sql = "SELECT * , MIN( price ) AS minPrice, MAX( price ) AS maxPrice, COUNT( id ) AS numMerchants, MATCH name AGAINST ('".database_safe($q)."') AS relevance FROM `".$config_databaseTablePrefix."products` WHERE MATCH name AGAINST ('".database_safe($q)."') GROUP BY name LIMIT ".$ln;
  }
  else
  {
    $sql = "SELECT * , MIN( price ) AS minPrice, MAX( price ) AS maxPrice, COUNT( id ) AS numMerchants FROM `".$config_databaseTablePrefix."products` WHERE search_name LIKE '%".database_safe($q)."%' GROUP BY name LIMIT ".$ln;
  }
  if (database_querySelect($sql,$rows))
  {
    foreach($rows as $row)
    {
      print "<item>";
      if ($config_useRewrite)
      {
        $href = "product/".tapestry_hyphenate($row["name"]).".html";
      }
      else
      {
        $href = "products.php?q=".urlencode($row["name"]);
      }
      print "<title>".$row["name"]."</title>";
      print "<link>http://www.example.com".$config_baseHREF.$href."</link>";
      print "<description>".$row["description"]."</description>";
      print "</item>";
    }
  }
  print "</channel>";
  print "</rss>";
?>

Hope this helps!
Cheers,
David.

Submitted by sbedigital on Sat, 2008-01-05 15:14

You are the best Dave :-)

Thanks a lot

Submitted by sbedigital on Mon, 2008-01-14 21:56

Sorry Dave one more help. How do I limit the number of characters used in feed item's tag TITLE and DESCRIPTION.
Lets says I want 70 characters in TITLE tag and 200 Characters in DESCRIPTION tag?

Submitted by support on Mon, 2008-01-14 22:01

Hi,

You can use PHP's substr() function to do that... here's the code:

      print "<title>".substr($row["name"],0,70)."</title>";
      print "<link>http://www.example.com".$config_baseHREF.$href."</link>";
      print "<description>".substr($row["description"]0,200)."</description>";

Cheers!
David.

Submitted by sbedigital on Mon, 2008-01-14 22:47

Tried that but I'm getting following error:

Parse error: syntax error, unexpected T_LNUMBER in /public_html/prodfeed.php on line 34

Submitted by sbedigital on Mon, 2008-01-14 22:49

I'm not sure whether this matters or not but I tell you anyway. I am running on PHP5

Submitted by support on Mon, 2008-01-14 22:54

Hi,

Sorry - there was a comma missing in the strpos() code for the description field - here's the correct code:

      print "<title>".substr($row["name"],0,70)."</title>";
      print "<link>http://www.example.com".$config_baseHREF.$href."</link>";
      print "<description>".substr($row["description"],0,200)."</description>";

Cheers,
David.

Submitted by sbedigital on Mon, 2008-01-14 22:58

Thanks for the reply but I have figured that out. {links saved}

By the way thank you for sloving this for me.

Submitted by support on Tue, 2008-01-15 10:26

Hi,

No worries! I took a look at the links - it's looking good!

Cheers,
David.

Submitted by sbedigital on Sun, 2008-01-27 18:15

now the most pleasing bit..... take a look {link saved} and do a search for "SONY DVD PLAYERS" and see the live feeds from BestBuyers.co.uk

Thanks to you Dave!