dude753 Posted April 22, 2009 Share Posted April 22, 2009 Hi there, I'm using a module called AG My Auctions in my Joomla site to display my eBay auctions in the footer of the page. I won't always have auctions running, so I'd like it to show a message when there are none. I used to be able to make my own basic PHP scripts so would have thought I could do this but apparently not. The code is: <?php /** * Modulo Sagre in Italia". */ // no direct access defined( '_JEXEC' ) or die( 'Restricted access' ); function getFeedAGMyAuctions($feed_url, $max_items) { $countitems=1; $content = file_get_contents($feed_url); $x = new SimpleXmlElement($content); echo "<table border='0' cellpadding='0'><tr>"; foreach($x->channel->item as $entry) { echo "<td><a href='$entry->link' title='$entry->title'>" . $entry->title . "</a>"; echo str_replace ("$" , "$ ", $entry->description); echo "</td>"; $countitems+=1; if ($countitems>$max_items) { break; } } echo "</tr></table>"; } $maxitems=$params->get('maxitems'); $feedurl="http://rss.api.ebay.com/ws/rssapi?FeedName=SearchResults&siteId=0&satitle=(".$params->get('keyword1').",".$params->get('keyword2').",".$params->get('keyword3').")&language=".$params->get('language')."&output=RSS20&sass=".$params->get('username')."&frpp=2&rows=2"; getFeedAGMyAuctions($feedurl, $maxitems); I've tried things like echoing an error message if $countitems == 0 but for some reason can't get anything to display. Quite frustrated that I haven't worked it out. Anybody able to point me in the right direction? Thanks a lot, Link to comment https://forums.phpfreaks.com/topic/155252-error-message-for-empty-rss-feed/ Share on other sites More sharing options...
dude753 Posted April 27, 2009 Author Share Posted April 27, 2009 Hi there, I never did manage to solve this myself. I had a thorough look on Google and found a lot of people asking how to deal with empty RSS feeds but no answers. Could anybody alter the code to provide an error message if the feed is empty? Thanks for your patience! Link to comment https://forums.phpfreaks.com/topic/155252-error-message-for-empty-rss-feed/#findComment-820191 Share on other sites More sharing options...
sloth456 Posted April 27, 2009 Share Posted April 27, 2009 Perhaps this would work? I'm not certain tbh. <?php /** * Modulo Sagre in Italia". */ // no direct access defined( '_JEXEC' ) or die( 'Restricted access' ); function getFeedAGMyAuctions($feed_url, $max_items) { $countitems=1; $content = file_get_contents($feed_url); $x = new SimpleXmlElement($content); echo "<table border='0' cellpadding='0'><tr>"; //my addition if(!empty($x->channel->item)){ foreach($x->channel->item as $entry) { echo "<td><a href='$entry->link' title='$entry->title'>" . $entry->title . "</a>"; echo str_replace ("$" , "$ ", $entry->description); echo "</td>"; $countitems+=1; if ($countitems>$max_items) { break; } } else { echo "Error message here"; } } echo "</tr></table>"; } $maxitems=$params->get('maxitems'); $feedurl="http://rss.api.ebay.com/ws/rssapi?FeedName=SearchResults&siteId=0&satitle=(".$params->get('keyword1').",".$params->get('keyword2').",".$params->get('keyword3').")&language=".$params->get('language')."&output=RSS20&sass=".$params->get('username')."&frpp=2&rows=2"; getFeedAGMyAuctions($feedurl, $maxitems); Link to comment https://forums.phpfreaks.com/topic/155252-error-message-for-empty-rss-feed/#findComment-820303 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.