• Login
  • Register
  • Zoek
This Thread
  • Everywhere
  • This Thread
  • This Forum
  • Articles
  • Pages
  • Forum
  • Filebase Entry
  • More Options

ICTscripters

Dé plek voor IT

Dé plek voor IT

Login

Geavanceerde opties
  1. Home
  2. Forum
    1. Alle berichten
    2. Recente activiteiten
  3. ICT Nieuws
  4. Blog
  5. Marktplaats
    1. Werk
    2. Advertenties
    3. Domeinnamen
    4. Websites
    5. Design & lay-outs
    6. Scripts
    7. Overige
  6. Design
  7. Leden
    1. Actieve bezoekers
    2. Team
    3. Leden zoeken
  8. Downloads
  9. Goedkope domeinnamen
  1. Home
  2. Forum
    1. Alle berichten
    2. Recente activiteiten
  3. ICT Nieuws
  4. Blog
  5. Marktplaats
    1. Werk
    2. Advertenties
    3. Domeinnamen
    4. Websites
    5. Design & lay-outs
    6. Scripts
    7. Overige
  6. Design
  7. Leden
    1. Actieve bezoekers
    2. Team
    3. Leden zoeken
  8. Downloads
  9. Goedkope domeinnamen
  1. Home
  2. Forum
    1. Alle berichten
    2. Recente activiteiten
  3. ICT Nieuws
  4. Blog
  5. Marktplaats
    1. Werk
    2. Advertenties
    3. Domeinnamen
    4. Websites
    5. Design & lay-outs
    6. Scripts
    7. Overige
  6. Design
  7. Leden
    1. Actieve bezoekers
    2. Team
    3. Leden zoeken
  8. Downloads
  9. Goedkope domeinnamen
  1. Dé plek voor IT - ICTscripters
  2. Forum
  3. Scripting & programmeren
  4. PHP + SQL

Forum

  • Na 15 jaar terug van weggeweest: iCriminals.nl is terug (BETA)!

    Syntax 19 januari 2026 om 09:34
  • Developer Gezocht

    Mikevdk 10 januari 2026 om 18:57
  • Op zoek naar de legends

    Syntax 5 januari 2026 om 13:50
  • [FREE] WeFact Hosting module

    Jeroen.G 13 oktober 2025 om 14:09
  • Help testers nodig voor android app Urgent

    urgentotservices 26 september 2025 om 10:21
  • Versio vervanger

    Jeroen.G 25 augustus 2025 om 15:56
  • Afspraken systeem met planbeperking

    Lijno 1 augustus 2025 om 23:04
  • Partner Gezocht om meerdere NFT Collecties op Open Sea te Plaatsen

    NFT Art Designer 1 maart 2025 om 14:08

Marktplaats

  • Verschillende domeinen

    Syntax 8 februari 2026 om 09:57
  • 350 Nieuwe Domeinnamen Januari 2026

    shiga 1 februari 2026 om 14:21
  • 321 Nieuwe Domeinnamen December 2025

    shiga 1 januari 2026 om 10:26

PHP row

  • Shahiem
  • 10 december 2010 om 22:12
  • Shahiem
    http://www.hogwartscastle
    Berichten
    216
    • 10 december 2010 om 22:12
    • #1

    Hey,

    Ik ben bezig met een webshop affiliatie site maar nu probeer ik de merken van de producten in te laden via een XML bestand. Alleen is het in de xml dat er merken dubbel staan, dus elk product heeft een merk en die laadt hij dan ook in.

    Weet iemand hoe ik gewoon een merk maar 1 keer in de database kan zetten?
    Dus niet dat hij steeds dubbel komt te staan.

    Code

    PHP
    <?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)
    {    
        mysql_query("INSERT INTO
                           merken
                        (
                            merk_naam
                        ) VALUES (
                            '".$core->mysql->escape(stripslashes($pChild->brand))."'
                                                                                                        
                        )") or die(mysql_error());
        $merk = $core->mysql->query("SELECT
                                            *
                                    FROM
                                        merken
                                    WHERE
                                        merk_naam = '".$core->mysql->escape(stripslashes($pChild->brand))."'");
        $merkf = $core->mysql->fetch($merk);
      
            
                        
        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."',   
                            '".$core->mysql->escape(stripslashes($pChild->category))."',
                            '".$pChild->img_medium."', 
                            '".$pChild->daisycon_unique_id."',
                             '".$core->mysql->escape(stripslashes($pChild->sub_sub_category))."',
                             '".$core->mysql->escape(stripslashes($pChild->sub_category))."',
                             '".$merkf['id']."'                                                                                 
                        )") or die(mysql_error());
     
                    
        // 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

    Gegroet :)

    [center]HogwartsCastle[/center]

  • Darsstar
    Vreemd
    Berichten
    1.173
    • 10 december 2010 om 22:33
    • #2

    Door een UNIQUE CONSTRAINT op het veld merk_naam in de tabel merken?

    miauw!

  • Shahiem
    http://www.hogwartscastle
    Berichten
    216
    • 11 december 2010 om 10:06
    • #3

    Dat lukt, maar nu als ik me xml import dan voegt hij maaar 3 producten toe en ook 3 merken.

    En ik krijg ook dit te zien: Duplicate entry 'Aeg' for key 'CONSTRANT'

    [center]HogwartsCastle[/center]

  • Darsstar
    Vreemd
    Berichten
    1.173
    • 11 december 2010 om 10:52
    • #4

    Ik kan op het moment twee dingen bedenken:
    1. haal de or die weg
    2. gebruik de INSERT INTO ... ON DUPLICATE KEY UPDATE syntax

    miauw!

  • Shahiem
    http://www.hogwartscastle
    Berichten
    216
    • 11 december 2010 om 13:25
    • #5

    Jij bent de beste :D Tien maal dank

    [center]HogwartsCastle[/center]

  • Shahiem
    http://www.hogwartscastle
    Berichten
    216
    • 11 december 2010 om 13:39
    • #6

    Ja graag :)

    [center]HogwartsCastle[/center]

  • K.Rens
    Eigenaar
    Ontvangen Reacties
    241
    Berichten
    4.473
    Filebase Entries
    2
    • 11 december 2010 om 14:25
    • #7

    En als je geen DB check wil doen, kan je gewoon de merken in een array steken en dan nadien met de in_array functie kijken of het merk al in de array zit of niet.
    Of het bv opslagen in een SESSION.

  • Shahiem
    http://www.hogwartscastle
    Berichten
    216
    • 11 december 2010 om 14:52
    • #8

    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
    <?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

    [center]HogwartsCastle[/center]

Participate now!

Heb je nog geen account? Registreer je nu en word deel van onze community!

Maak een account aan Login

ICT Nieuws

  • Fijne feestdagen

    tcbhome 28 december 2025 om 13:55
  • Kritieke update voor Really Simple Security-plug-in

    K.Rens 16 november 2024 om 16:12
  • ING Nederland streeft naar ondersteuning van Google Pay tegen eind februari

    K.Rens 2 november 2024 om 16:09

Blogs

  • Functioneel ontwerp

    Dees 28 december 2014 om 12:38
  • Access Control List implementatie in PHP/MySQL - deel 1/2

    FangorN 28 december 2018 om 12:35
  • Access Control List implementatie in PHP/MySQL - deel 2/2

    FangorN 29 december 2018 om 12:37

Gebruikers die dit topic bekijken

  • 1 Gasten
  1. Marktplaats
  2. Design
  3. Voorwaarden
  4. Ons team
  5. Leden
  6. Geschiedenis
  7. Regels
  8. Links
  9. Privacy Policy
ICTscripters ©2005 - 2026 , goedkope hosting door DiMoWeb.com, BE0558.915.582
Sponsors: Beste kattenhotel provincie Antwerpen | Beste Zetes eid kaartlezer webshop
Style: Nexus by cls-design
Stylename
Nexus
Manufacturer
cls-design
Licence
Commercial styles
Help
Supportforum
Visit cls-design