Bijna alles werkt momenteel in mijn script, het enige probleem zit nog bij het ophalen van image url's.
Twee vragen:
In de database staan namelijk allemaal dezelfde url's bij verschillende artikels. Hoe kun je ervoor zorgen dat bij ieder artikel de bijpassende image url opgehaald wordt?
En als er geen image url is er geen wordt toegevoegd aan de database en pas bij de volgende weer een url toevoegd?
Alvast hartelijk dank!
<?php
//For the "populate your data" video from the PHP RSS feed tutorial video on http://phprox.com save this file as cron.php in your news folder
include_once "scripts/connect_all.php";
// the line below sets the feed parser to loop through multiple news sources eaxample: for($x = 0; $x < 5; $x++) will run 5 times. Change the 5 to
//the total number of broadcaster websites you want this job to loop through during each script run. The { begins the "script nest8 which continues
// until it reaches the last } at the end of this script.
for($x = 0; $x < 5; $x++) {
$sqlCommand = "SELECT * FROM feeds_list WHERE cron_file='2' ORDER BY cron ASC LIMIT 1";
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error());
while ($row = mysqli_fetch_array($query)) {
$feed_id = $row["feed_id"];
$feed_name = $row["feed_name"];
$feed_name = html_entity_decode($feed_name);
$feed_subject = $row["feed_subject"];
$feed_url = $row["feed_url"];
$feed_country = $row["feed_country"];
$feed_length = $row["feed_length"];
}
mysqli_free_result($query);
$html = "";
$url = "$feed_url";
$xml = simplexml_load_file($url);
for($i = 0; $i < $feed_length; $i++) {
$title = $xml->channel->item[$i]->title;
$description = $xml->channel->item[$i]->description;
$link = $xml->channel->item[$i]->link;
$pubDate = $xml->channel->item[$i]->pubDate;
$author = $xml->channel->item[$i]->author;
$feed2 = simplexml_load_file($feed_url);
foreach ($feed2->channel->item as $item) {
if ($media = $item->children('media', TRUE)) {
if ($media->content->thumbnail) {
$attributes = $media->content->thumbnail->attributes();
$image = (string)$attributes['url'];
}
}
}
//$html .= "<div><h3><a href='$link'target='_blank'>$title</a></h3></div>$pubDate<br/>$author<br/><br/>$description<hr />";
$title1 =str_replace("'","\'",$title);
$description1 =str_replace("'","\'",$description);
$author1 =str_replace("'","\'",$author);
$sql = mysql_query("INSERT IGNORE INTO feeds (feed_id, pubDate, title, description, link, author, image, country, feed_subject, log_time) VALUES('$feed_id','$pubDate','$title1','$description1','$link','$author','$image','$feed_country','$feed_subject',now()) ") or die (mysql_error());
$sql = mysql_query("UPDATE `feeds_list` SET `cron` = now() WHERE feed_id ='$feed_id'")or die (mysql_error());
}
}
?>
1.438 views