Code Comments
Programming Forum and web based access to our favorite programming groups.i would like to create a web spider to search for rss feeds and input the articles or data from those feeds into a mysql database. i have tried many times to do this but for some reason when i try to insert them into the mysql database it will only insert the last article on the feed so what can i do to place them all?
Post Follow-up to this messagewell my first question,(probably don't need to ask it) but is it deffinatly returning the entire lot of RSS feeds to you, is it just the entering data thats going wrong or is it that you are not actually recieving the first feeds just the last one.
Post Follow-up to this messagewell my first question,(probably don't need to ask it) but is it deffinatly returning the entire lot of RSS feeds to you, is it just the entering data thats going wrong or is it that you are not actually recieving the first feeds just the last one.
Post Follow-up to this messagewhen i display them they all show up, its only the last one of those
that are displayed that will be inserted into the mysql database
here is te code
<?php
require_once '../Content/rss_fetch.inc';
$url = 'http://www.usatoday.com/repurposing/NBARss.xml' ;
$rss = fetch_rss($url);
echo 'Site: ' , $rss->channel['title'], ' <br / >';
if ( $rss and !$rss->ERROR) {
foreach ($rss->items as $item ) {
echo ' <p><a href="' . $item[link] . '">' . $item[title] . '
</a><br / >';
echo 'Publish Date: ' . $item[pubdate] . ' <br / >';
echo $item[ description ] . ' </p>' ;
}
} else {
echo 'RSS Error: ' . $rss->ERROR . ' <br / ><br />' ;
}
include("connect.php");
//Item Info
$Added=date(Ymd);
$Item_Title=$item[title];
$Item_Link=$item[link];
$Item_Category=$item[category];
$Item_PubDate=$item[pubdate];
$Item_Description=$item[description];
$add = "INSERT INTO Articles VALUES (NULL, '$Item_Title',
'$Item_Category', '$SubCategory', '$Added',
'$Item_PubDate','$Item_Link', '$Item_Description')";
$result=mysql_query("$add");
mysql_close($connection);
?>
Post Follow-up to this messagewhen i display them they all show up, its only the last one of those
that are displayed that will be inserted into the mysql database
here is te code
<?php
require_once '../Content/rss_fetch.inc';
$url = 'http://www.usatoday.com/repurposing/NBARss.xml' ;
$rss = fetch_rss($url);
echo 'Site: ' , $rss->channel['title'], ' <br / >';
if ( $rss and !$rss->ERROR) {
foreach ($rss->items as $item ) {
echo ' <p><a href="' . $item[link] . '">' . $item[title] . '
</a><br / >';
echo 'Publish Date: ' . $item[pubdate] . ' <br / >';
echo $item[ description ] . ' </p>' ;
}
} else {
echo 'RSS Error: ' . $rss->ERROR . ' <br / ><br />' ;
}
include("connect.php");
//Item Info
$Added=date(Ymd);
$Item_Title=$item[title];
$Item_Link=$item[link];
$Item_Category=$item[category];
$Item_PubDate=$item[pubdate];
$Item_Description=$item[description];
$add = "INSERT INTO Articles VALUES (NULL, '$Item_Title',
'$Item_Category', '$SubCategory', '$Added',
'$Item_PubDate','$Item_Link', '$Item_Description')";
$result=mysql_query("$add");
mysql_close($connection);
?>
Post Follow-up to this messagemysitesucks@gmail.com wrote:
> when i display them they all show up, its only the last one of those
> that are displayed that will be inserted into the mysql database
>
> here is te code
> <?php
> require_once '../Content/rss_fetch.inc';
>
> $url = 'http://www.usatoday.com/repurposing/NBARss.xml' ;
> $rss = fetch_rss($url);
>
> echo 'Site: ' , $rss->channel['title'], ' <br / >';
> if ( $rss and !$rss->ERROR) {
> foreach ($rss->items as $item ) {
> echo ' <p><a href="' . $item[link] . '">' . $item[title] . '
> </a><br / >';
> echo 'Publish Date: ' . $item[pubdate] . ' <br / >';
> echo $item[ description ] . ' </p>' ;
> }
> } else {
> echo 'RSS Error: ' . $rss->ERROR . ' <br / ><br />' ;
> }
>
> include("connect.php");
>
> //Item Info
> $Added=date(Ymd);
> $Item_Title=$item[title];
> $Item_Link=$item[link];
> $Item_Category=$item[category];
> $Item_PubDate=$item[pubdate];
> $Item_Description=$item[description];
> $add = "INSERT INTO Articles VALUES (NULL, '$Item_Title',
> '$Item_Category', '$SubCategory', '$Added',
> '$Item_PubDate','$Item_Link', '$Item_Description')";
> $result=mysql_query("$add");
> mysql_close($connection);
> ?>
>
Of course it only puts the last one in the database. You don't have the
db related code within your loop.
It goes through and displays everything. Then after the last one is
displayed, it inserts the current (last) item in the database.
Put your insert code within the loop and it should work better.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Post Follow-up to this messagethanls alot i have tried doing this for a month now and every one i ask they don't know, but thank you very much
Post Follow-up to this messageWould you know any place where i can learn how to make a web spider? and some good code examples or scripts?
Post Follow-up to this messageO'Reilly Perl & LWP has some good scripts. Use them as a starting point. Translating to php wouldn't be required. But doing so not all that hard.
Post Follow-up to this messageok thanks, do u know any books to do it in php?
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.