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>
Any HELP????
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.
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.
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?
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.
Tried that but I'm getting following error:
Parse error: syntax error, unexpected T_LNUMBER in /public_html/prodfeed.php on line 34
I'm not sure whether this matters or not but I tell you anyway. I am running on PHP5
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.
Thanks for the reply but I have figured that out. {links saved}
By the way thank you for sloving this for me.
Hi,
No worries! I took a look at the links - it's looking good!
Cheers,
David.
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!
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.