Jump to content

Error message for empty RSS feed


dude753

Recommended Posts

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

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!

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);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.