Jump to content


Photo

Where write my loop in this php script ?


  • Please log in to reply
2 replies to this topic

#1 bef1rst

bef1rst
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 16 July 2006 - 08:42 AM

Hello,

I would like to use a loop in order to use different feed rss in this script but i don't know where i must put it.

<?
require('rss_fetch.inc');

include('../config.php');
require(mnminclude.'link.php');

$rss_feeds=array(
        array(
                'url'=>"http://feeds.feedbur...r.com/rss2.xml",
                'category'=>15,
                'author'=>15,
                'tags'=>"tags1"
        ),
);

echo "<ul>\n";
foreach ($rss_feeds as $feed ) {
$rss = fetch_rss($feed['url']);
echo "<li>Site: ", $rss->channel['title'], "<br>\n";
foreach ($rss->items as $item )
{

if ($i <= 10)
    {
        $item['author']=$feed['author'];
        $item['category']=$feed['category'];

        $title = $item[title];
        $desc= $item[description];

        echo "<ul>";
        echo "<li>Processing <a href=$url>$title</a></li>\n";
        rss_store($item);
        echo "<li>Finished Processing <a href=$url>$title</a></li><br><br/>\n\n";
        echo "</ul>";
    }
    $i++;

}
echo "</li>";
}
echo "</ul>";


function rss_store($item) {

        $linkres=new Link;

        $edit = false;
        $linkres->get(trim($item['link']));

        if(!$linkres->valid) {
                rss_error($item['link']);
                return;
        }

        if($linkres->duplicates($item['link']) > 0) {
                rss_error($item['url']);
                return;
        }
        $linkres->status='discard';
        $linkres->author=$item['author'];

        $linkres->title=$item['title'];
        $linkres->content=$item['description'];


        $linkres->id=0;
        $linkres->category=$item['category'];
        $linkres->randkey=rand(10000,10000000);
        $linkres->read();
        $linkres->status='queued';
        $linkres->store();
        return;
}

function rss_error($url){
        echo "Skipped $url <br/>\n";
}


?>


This script works and i just would like to put different feed. I would like to create a table in my mysql database in order to write the different feed. I have already do this job.

Thanks for your answers.

#2 PC Nerd

PC Nerd
  • Members
  • PipPipPip
  • Advanced Member
  • 1,122 posts
  • LocationAustralia

Posted 16 July 2006 - 12:22 PM

i didnt read all the script, but the following might work

$feed = "INPUT FROM FEILD"

include('inc_files/'.$feed/"'");

simply save your different feeds as seperate inc files.

you could also create an array, which could check the input, to that sent data could be simply 1, 2,3 ,4 5, 6 7 ,8 8 etc.

good luck

#3 bef1rst

bef1rst
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 16 July 2006 - 05:11 PM

Thanks for your answer. I will test as soon as possible.

I have another idea: I made a request in MYSQL who take the URL of the feed in a table of a database. It's better for the organisation of the feed because i can create an administrator acces etc.

I thnik that my request could be at the beginning of this part of the script:

$query = "SELECT url FROM feed"; 
$result = mysql_query($query);

while ($val = mysql_fetch_array($result)) {
   
$rss_feeds=array(
        array(
                'url'=>"$url",
                'category'=>15,
                'author'=>15,
                'tags'=>"tags1"
        ),
);

} ?>



What do you think of that ? Thanks for your answers.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users