Hi

I have looked around the forum but cant find anything about rss feed links. I have managed to get my rss feed working but i want users to be able to click on the title of the rss to take them bk to the orignal website can anyone tell me how to do this.

<?
    
$dbServer=mysql_connect("localhost","","");
if (!$dbServer) {echo "Failed to connect to MySQL"; exit; }
mysql_select_db("",$dbServer);  

   

  
  // Get latest items from db
  $sql = "SELECT * FROM messages ORDER BY date_added DESC limit 0,10";
  $rst = mysql_query($sql);
  
  // Loop through data and build feed items
  $items = "";
  while($a_row = mysql_fetch_assoc($rst))
  {
    $items.= "<item>";
    $items.= "  <title>{$a_row['title']}</title>";
    $items.= "  <link>{$a_row['link']}</link>";
    $items.= "  <description>{$a_row['message']}</description>";
    $items.= "  <description>{$a_row['date_added']}</description>";
    $items.= "</item>"; 
  }
  
  // Build feed text
  $feed = "<?xml version=\"1.0\"?>";
  $feed.= "<rss version=\"2.0\">";
  $feed.= "  <channel>";
  $feed.= "    <title> blog feed</title>";
  $feed.= "    <link>http://mi-linux.../~/index.php</link>";
  $feed.= "    <description>A cool feed</description>";
  $feed.= "    $items";
  $feed.= "  </channel>";
  $feed.= "</rss>";
  
  // Display feed text
  echo $feed;
?>

Recommended Answers

All 8 Replies

Your rss reader should provide this (Internet Explorer does this), but not all do (Opera doesn't).

but if i feed from an rss to my website using this code it does not give me a link to each of the news stories that are listed how would i do that

<?
$feed_url = "http://www.skysports.com/rss/0,20514,13187,00.xml";

  // Get data from feed file
  $response = file_get_contents($feed_url);
  $items.= "  <link>{$a_row['link']}</link>";
    
  // Insert XML into structure
  $xml = simplexml_load_string($response); 
   
  // Browse structure
  foreach($xml->channel->item as $one_item)
    echo $one_item->title."<BR>"; 
    
?>
 
<a title="Link 5" href="http://www.skysports.com/">Sky Sports news website</a></div>

$a_row is undefined.

could u pls tell me what i need to put in the code to get to link all the news stories so the link takes me back to the news story

You need to output the link in an a tag, around the title.

commented: Thanks for the rep today.:) +7

i have managed to get this far see below and this code lists the links buti still cant click on them what do i do now pls help.

<?
$feed_url = "http://www.skysports.com/rss/0,20514,13187,00.xml";

  // Get data from feed file
  $response = file_get_contents($feed_url);
  
    
  // Insert XML into structure
  $xml = simplexml_load_string($response); 
   
  // Browse structure
  foreach($xml->channel->item as $one_item)
  echo $one_item->title. $one_item-> link. "<BR>";  
    
        
    
?>
echo '<a href="' . $one_item->link . '">' . $one_item->title . '</a><br/>';

thank u very much!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.