|
Posted by Jerry Stuckle on 11/09/37 11:42
mysitesucks@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
==================
[Back to original message]
|