Почему в базе данных происходит двойной дубль сериалов из xml?
0
Почему в базе данных происходит двойной дубль сериалов из xml, первый раз под категорией фильмы?
<?php
function insert($name, $desc, $year, $category_id, $rating, $poster)
{
$mysqli = new mysqli('localhost', 'root', '', 'kinomonster');
if (mysqli_connect_errno())
{
print_f("Cоединение не установлено", mysqli_connect_error());
exit();
}
$mysqli->set_charset('utf8');
$query = "INSERT INTO movie VALUES(null, '$name', '$desc', '$year', NOW(), '$category_id', '$rating', '$poster')";
$result = false;
if ($mysqli->query($query))
{
$result = true;
}
return $result;
}
$xml = simplexml_load_file("xml/movies.xml") or die("Cannot create object");
//echo count($xml);//
$title = null;
$title_orign = null;
$post = null;
$rating = null;
$year = null;
foreach ($xml as $movie_key => $movie)
{
$title = $movie->title_russian;
$title_orign = $movie->title_original;
$year = $movie->year;
foreach ($movie
->poster
->big
->attributes() as $poster_key => $poster)
{
$post = $poster;
}
if ($movie->imdb)
{
$rating = $movie
->imdb
->attributes() ['rating'];
}
else
{
$rating = null;
}
insert($title, $title_orign, $year, 1, $rating, $post);
}
$xml2 = simplexml_load_file("xml/serials.xml") or die("Cannot create object");
//echo count($xml);//
$title = null;
$title_orign = null;
$post = null;
$rating = null;
$year = null;
foreach ($xml2 as $movie_key => $movie)
{
$title = $movie->title_russian;
$title_orign = $movie->title_original;
$year = $movie->year;
foreach ($movie
->poster
->big
->attributes() as $poster_key => $poster)
{
$post = $poster;
}
if ($movie->imdb)
{
$rating = $movie
->imdb
->attributes() ['rating'];
}
else
{
$rating = null;
}
insert($title, $title_orign, $year, 2, $rating, $post);
}
echo "<pre>";
print_r($xml);
print_r($xml2);
echo "</pre>";
?>