Click to See Complete Forum and Search --> : Price comparision help Please!!!


msd_luke
04-07-2009, 08:44 AM
Hi All,

ok i am trying to set up a price comparision feature on my site, i have several product feeds to use but i have a few problems.

1/ some of the product feeds contain too many products and i get an out of memory error. is there a way around this? my php limit is 24mb i think.

2/ im not sure how to insert all the required data into the db table so far i have
$xml=("http://ax.itunes.apple.com/WebObjects/MZStoreServices.woa/ws/RSS/topsongs/sf=143444/limit=10/explicit=true/xml?partnerId=2003&TD_PARAM=http://clkuk.tradedoubler.com/click?p=23708&a=1515427&url=");


$xmlDoc = new DOMDocument();
$xmlDoc->load($xml);

for ($i = 0; $i < 10; $i++) {
//get elements from "<channel>"
$channel=$xmlDoc->getElementsByTagName('entry')->item($i);

$channel_title =
mysql_real_escape_string($channel->getElementsByTagName('title')->item(0)->childNodes->item(0)->nodeValue);

$channel_image =
mysql_real_escape_string(str_replace("30x30-50","100x100-75",$channel->getElementsByTagName('image')->item(0)->childNodes->item(0)->nodeValue));

$channel_link =
mysql_real_escape_string($channel->getElementsByTagName('id')->item(0)->childNodes->item(0)->nodeValue);

$channel_album =
mysql_real_escape_string($channel->getElementsByTagName('name')->item(0)->childNodes->item(0)->nodeValue);

$channel_artist =
mysql_real_escape_string($channel->getElementsByTagName('artist')->item(0)->childNodes->item(0)->nodeValue);

$channel_cost =
mysql_real_escape_string($channel->getElementsByTagName('price')->item(0)->childNodes->item(0)->nodeValue);

//output elements from "<channel>"
$sql = "INSERT INTO product_database (pID, store, storeLink, productTitle, productLink, productIMG, description, price) VALUES ($i, 'itunes', '$channel_link', '$channel_artist - $channel_album', '$channel_link', '$channel_image', 'description here','$channel_cost')";
$query = mysql_query($sql);

echo ("<a href='$channel_link'>".$channel_title."</a>");
echo("<br />");
echo $channel_album;
echo("<br />");
echo $channel_artist;
echo("<br />");
echo $channel_cost;
echo("<br />");
echo ("<img src='$channel_image'>");
echo("<br />");
}

which work if i know the number of products but i dont know how to code the above for an unknown number of products

3/ what is the best way to do this?

any help would be greatly appreciated
Thanks
Luke

jkmyoung
04-07-2009, 04:36 PM
$channels=$xmlDoc->getElementsByTagName('entry');
for ($i = 0; $i < $channels.length; $i++) {
$channel = $channels->item($i);

msd_luke
04-07-2009, 04:49 PM
Hi mate, thanks for your reply

i have inserted your code and am getting this error

Catchable fatal error: Object of class DOMNodeList could not be converted to string in /customers/kernow-connect.com/kernow-connect.com/httpd.www/testfeed2.php on line 23

and this is line 23
for ($i = 0; $i < $channels.length; $i++) {


any ideas?
cheers
Luke

jkmyoung
04-08-2009, 11:10 AM
Probably $channels->length.
You could also use instead
foreach ($channels as $channel){

msd_luke
04-08-2009, 03:41 PM
hi mate,
thank you!!!! $channels->length worked a treat :)

one problem im having at the moment is when displaying just all the product titles linked to the url i dont get them all to display as i get a time out error
Fatal error: Maximum execution time of 30 seconds exceeded in /customers/kernow-connect.com/kernow-connect.com/httpd.www/testfeed2.php on line 23

althought in the end i dont want to display all the items will i get the same problem when trying to insert all the data into a table?

once again thanks for your help so far
Luke

EDIT
-----

i am also having difficulty getting the merchant name out here is an extract from a feed
<merchant id="1826" name="UKSoccershop.com">

<prod id="17704500" in_stock="no">
<pId>24</pId>

<text>
<name>Lanus home 04/05</name>

<desc>
Brand new, official 2004 soccer jersey. Fully authentic in bag with official tags, this item is imported from Argentina. Available in sizes S, M, L, XL. We can add a name and number to this item for &amp;pound;7.50. To select a name and number, choose Name and Number: Other and enter your requirements in the order comments box.
</desc>
</text>

<uri>

<awTrack>
http://www.awin1.com/pclick.php?p=17704500&a=79524&m=1826
</awTrack>

<awImage>
http://images.productserve.com/preview/1826/17704500.jpg
</awImage>
<mImage>http://www.uksoccershop.com/images/lanus_home.jpg</mImage>
</uri>

<price>
<buynow>39.99</buynow>
<store>0.00</store>
</price>

<cat>
<awCat>Football</awCat>
</cat>
<brand/>

here is what i tried
$channel_storename =
$xmlDoc->getElementsByTagName('merchant->name');
print $channel_storename;

but it says
Object of class DOMNodeList could not be converted to string

any ideas how i can pull out the merchant name?

cheers mate

dmboyd
04-08-2009, 04:31 PM
For your first question, I have no idea what you're doing, so I can't really help. :(

Regarding your other question about the merchant, when you use getElementsByTagName(), that function returns a DOMNodeList object, just as the error says. Notice the word "List" in there? By definition, that means there is more than one, which leads to the now obvious answer of using a loop to extract each merchant's data. Of course, if there was only one merchant, then you would need to simply reference it as $channel_storename->item(0) rather than using a loop to go through a single DOMNode item.

I hope this helps. ^_^

msd_luke
04-08-2009, 04:37 PM
hi mate thanks for your reply :)

im not sure i understand 100% lol yeah there is only one merchant in this feed but i my download them as one file in the future to make things easier :)
in trying to get the merchant name i have this before the loop
$xmlDoc = new DOMDocument();
$xmlDoc->load($xml);
$channels=$xmlDoc->getElementsByTagName('prod');

$channel_storename->item(0);//this is where im trying to get the merchant name
print $channel_storename;


but am getting
Fatal error: Call to a member function item() on a non-object in

thanks again for taking time to help :)
cheers
Luke

dmboyd
04-08-2009, 04:59 PM
I think you misinterpreted my post a little bit. :p

This is what I meant:
$channel_storename = $xmlDoc->getElementsByTagName('merchant->name');
// See how the item() function is used here?
print $channel_storename->item(0);

jkmyoung
04-08-2009, 06:25 PM
$merchant = $xmlDoc->getElementsByTagName('merchant')->item(0);
print $merchant->getAttribute('name')


http://phpbuilder.com/manual/en/function.dom-domelement-getattribute.php

msd_luke
04-09-2009, 07:42 AM
I think you misinterpreted my post a little bit. :p

This is what I meant:
$channel_storename = $xmlDoc->getElementsByTagName('merchant->name');
// See how the item() function is used here?
print $channel_storename->item(0);

lol im always misinterpreting things :) especially when its something i know very little about;

the above code does not print out anything :( but the code provided by jkmyoung works a treat so thank you both for your continued help on this project of mine :)

many thanks
Luke

msd_luke
04-09-2009, 07:43 AM
$merchant = $xmlDoc->getElementsByTagName('merchant')->item(0);
print $merchant->getAttribute('name')


http://phpbuilder.com/manual/en/function.dom-domelement-getattribute.php

cheers mate this works a treat thanks
Luke

p.s nice link, hopefully very useful...

msd_luke
04-09-2009, 07:50 AM
ok i think this is "hopefully" my last problem!!! :)

what i want to prevent is errors caused by one item not having the exact same nodes as the others

so if
item 1=>title,description,image,link,category,price
item 2=>title,description,image,link,category,price
item 3=>title,description,image,link,price

so is there a way that when pulling out the nodes values e.g
$channel_image =
mysql_real_escape_string($channel->getElementsByTagName('mImage')->item(0)->childNodes->item(0)->nodeValue);

i can check that the node exists and if not set the varible to "N/A" or something else so that i dont get an error when the php code tried to insert a non valid value?

does this make sence? :)

cheers
Luke

just been checking out the link above and have come accross hasAttribute which is what i think i would need to use for my above query?

jkmyoung
04-09-2009, 12:28 PM
seperate into parts, checking for null at each level:

$mImage = $channel->getElementsByTagName('mImage')->item(0);
if ($mImage != null && $mImage->childNodes->length > 0){
$channel_image = mysql_real_escape_string($mImage->childNodes->item(0)->nodeValue);
} else {
$channel_image = "";
}

msd_luke
04-09-2009, 12:50 PM
cheers mate i will look into this.

unfortunatly at the moment i am having trouble with my php as when trying to insert a large feed (5000+ items) into my mysql table it produces an error saying 30 second maximum time exceeded and only the items read up until that point were added to the db.

so im not sure what to do next? someone suggested using pearl?

any ideas
cheers