Forum Moderators: coopster
Right now I just have it displaying: echo "There is no news on $section."; if there is no news... Instead of displaying that I would like it to pull news using the variable $topic if it can't find any news from that section...
Here is the script:
<?php
$filename = "http://search.msn.com/news/results.aspx?q=$section&format=rss&FORM=RSNR";
$feed = implode('', file($filename));
preg_match_all('#<title>(.*?)</title>#', $feed, $title, PREG_SET_ORDER);
preg_match_all('#<link>(.*?)</link>#', $feed, $link, PREG_SET_ORDER);
preg_match_all('#<description>(.*?)</description>#', $feed, $description, PREG_SET_ORDER);
$nr = count($title);
if($nr == 1){
echo "There is no news on $section."; // Would I tell it to reset to $topic here?
}
elseif($nr > 1){
for ($counter = 1; $counter < 11; $counter++ ){
if(empty($title[$counter][1])){
echo "";
}
elseif(!empty($title[$counter][1])){
$title[$counter][1] = str_replace("&", "&", $title[$counter][1]);
$title[$counter][1] = str_replace("'", "'", $title[$counter][1]);
$description[$counter][1] = str_replace("&", "&", $description[$counter][1]);
$description[$counter][1] = str_replace("'", "'", $description[$counter][1]);
echo "<p>".$title[$counter][1]."</p>";
echo "<p>".$description[$counter][1]."</p>";
echo "<a href=\"".$link[$counter][1]."\">Read more</a><br>";
}
}
}
?>
Pseudo will be like:
$RecordSet=fetchNews($section);
if($RecordSet['count']==0)
{
$RecordSet2=fetchNews($topic);
}
I am sorry if i misunderstood your question.
Kami