Ik heb nog een vraag, hij doet soms een beetje raar.
In me producten tabel dan vult hij de category en zo wel maar soms vult hij de eerste 4 producten niet, dus die geeft hij geen category.
Screen: http://i54.tinypic.com/104qonn.png
Code
<?php
include '../includes/config.php';
// Load the XML data from the specified file name.
// The second argument (NULL) allows us to specify additional libxml parameters,
// we don't need this so we'll leave it as NULL. The third argument however is
// important as it informs simplexml to handle the first parameter as a file name
// rather than a XML formatted string.
$pFile = new SimpleXMLElement('http://hardsoftware.nl/xml/elektrokoopjes.xml', null, true);
// Now that we've loaded our XML file we can begin to parse it.
// We know that a channel element should be available within the,
// document so we begin by looping through each channel
foreach ($pFile->item as $pChild)
{
$merk = $core->mysql->query("SELECT
*
FROM
merken
WHERE
merk_naam = '".$core->mysql->escape(stripslashes($pChild->brand))."'");
$merkf = $core->mysql->fetch($merk);
$rubriek = $core->mysql->query("SELECT
*
FROM
rubriek
WHERE
naam = '".$core->mysql->escape(stripslashes($pChild->category))."'");
$rubriekFetch = $core->mysql->fetch($rubriek);
$subsubrubriek = $core->mysql->query("SELECT
*
FROM
subsubrubrieken
WHERE
subsub_omschrijving = '".$core->mysql->escape(stripslashes($pChild->sub_sub_category))."'");
$subsubrubriekFetch = $core->mysql->fetch($subsubrubriek);
$subrubriek = $core->mysql->query("SELECT
*
FROM
subrubrieken
WHERE
sub_omschrijving = '".$core->mysql->escape(stripslashes($pChild->sub_category))."'") or die(mysql_error());
$subrubriekFetch = $core->mysql->fetch($subrubriek);
// Merk
mysql_query("INSERT INTO
merken
(
merk_naam
) VALUES (
'".$core->mysql->escape(stripslashes($pChild->brand))."'
)
ON DUPLICATE KEY UPDATE merk_naam = '".$core->mysql->escape(stripslashes($pChild->brand))."'");
// Rubriek
mysql_query("INSERT INTO
rubriek
(
naam
) VALUES (
'".$core->mysql->escape(stripslashes($pChild->category))."'
)
ON DUPLICATE KEY UPDATE naam = '".$core->mysql->escape(stripslashes($pChild->category))."'");
mysql_query("INSERT INTO
subsubrubrieken
(
subid,
subsub_omschrijving
) VALUES (
'".$subrubriekFetch['id']."',
'".$core->mysql->escape(stripslashes($pChild->sub_sub_category))."'
)
ON DUPLICATE KEY UPDATE subsub_omschrijving = '".$core->mysql->escape(stripslashes($pChild->sub_sub_category))."'") or die(mysql_error());
mysql_query("INSERT INTO
subrubrieken
(
rubriek_id,
sub_omschrijving
) VALUES (
'".$rubriekFetch['id']."',
'".$core->mysql->escape(stripslashes($pChild->sub_category))."'
)
ON DUPLICATE KEY UPDATE sub_omschrijving = '".$core->mysql->escape(stripslashes($pChild->sub_category))."'") or die(mysql_error());
if($core->mysql->num_rows($merk) >= 0)
{
mysql_query("INSERT INTO
producten
(
naam,
link,
beschrijving,
prijs,
cat,
afbeelding_groot,
daisycon_id,
subcat,
subsubcat,
merk_product
) VALUES (
'".$core->mysql->escape(stripslashes($pChild->title))."',
'".$core->mysql->escape(stripslashes($pChild->link))."',
'".$core->mysql->escape(stripslashes($pChild->description))."',
'".$pChild->minimum_price."',
'".$rubriekFetch['id']."',
'".$pChild->img_medium."',
'".$pChild->daisycon_unique_id."',
'".$subrubriekFetch['id']."',
'".$subsubrubriekFetch['id']."',
'".$merkf['id']."'
)");
}
// Print our channel specific information, this should be
// easy to understand, basically we're grabbing the
// title, descripting and link nodes and outputting their values
echo "<h1>" . $pChild->title . "</h1>\n";
echo "IMG: ".$pChild->category." en sub ".$pChild->sub_category."<p>\n";
echo $pChild->description . "<br />\n";
printf('Visit us at <a href="%s">%s</a><br />' . "\n", $pChild->link, $pChild->link);
echo "</p>\n";
// Now we want to loop through the items inside this channel
foreach ($pFile->general->item as $pItem)
{
echo "<p>\n";
// If this item has child nodes as it should,
// loop through them and print out the data
foreach ($pItem->general() as $pChild)
{
// We can check the name of this node using the getName() method.
// We can then use this information, to, for example, embolden
// the title or format a link
switch ($pChild->getName())
{
case 'title':
echo "<b>$pChild</b><br />\n";
break;
case 'link':
printf('<a href="%s>%s</a><br />' . "\n", $pChild, $pChild);
break;
default:
echo nl2br($pChild) . "<br />\n";
break;
}
}
echo "</p>\n";
}
}
?>
Toon Meer