Reply to XML to mySQL - Loop issue?

Your name:

Reply:


Posted by Sarah on 10/28/07 18:15

Hi -

I am relatively new to PHP and mySQL. I am trying to loop through a
bunch of
XML feeds, pull out some info and place it into a mySQL table. I am
able to loop through the feeds, pull out all the relevant info and
print
it to my browser with no problem using simpleXML for the parsing.
When I try inserting the variables into mySQL instead of printing the
variables to the browser it will only pull the first item and date
from each XML page instead of all of the data. I have no idea
why this would be. Any ideas? Here is the code I have so far:

<?php
$con2 = mysql_connect("localhost","USER", "PASS");
if (!$con2)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("DATABASE", $con2);


$entriesinsert = 0;


$resultBlogsMarket = mysql_query("SELECT * FROM myspacepages");


while($rowMarket = mysql_fetch_array($resultBlogsMarket))
{
$myspaceid = $rowMarket['friendid'];
$myspacemarket = $rowMarket['market'];
$myspaceblogURL = "http://blog.myspace.com/blog/rss.cfm?friendID=".
$myspaceid;


// Load and parse the XML document
$rss = simplexml_load_file($myspaceblogURL);


// Here we'll put a loop to include each item's title and date
foreach ($rss->channel->item as $item)
{
$titlequotes = "'".$item->title."'";
$formattedDate = "'".date("Y-m-d H:i:s", strtotime($item-
>pubDate))."'";
$myspaceidquotes = "'".$myspaceid."'";


$resultBlogs = mysql_query("SELECT friendid, title, pubDate FROM
blogs WHERE friendid=$myspaceidquotes AND pubDate=$formattedDate AND
title=$titlequotes");


if (mysql_num_rows($resultBlogs)=="0")
{
mysql_query("INSERT INTO blogs (friendid, title, pubDate)
VALUES ($myspaceidquotes, $titlequotes, $formattedDate)");
$affectedrows=mysql_affected_rows();
if($affectedrows=="1")
{
$entriesinsert++;
}
}
}
}


echo $entriesinsert." entries inserted. Done!";

mysql_close($con2);
?>

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация