• Inloggen
  • Registreer
  • Zoeken
Dit topic
  • Overal
  • Dit topic
  • Dit forum
  • Artikelen
  • Pagina's
  • Forum
  • Downloads
  • Meer opties

ICTscripters

Dé plek voor IT

Dé plek voor IT

Aanmelden

Geavanceerde opties
  1. Home
  2. Forum
    1. Alle berichten
    2. Recente activiteiten
    3. Onopgeloste topics
  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
  1. Home
  2. Forum
    1. Alle berichten
    2. Recente activiteiten
    3. Onopgeloste topics
  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
  1. Home
  2. Forum
    1. Alle berichten
    2. Recente activiteiten
    3. Onopgeloste topics
  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
  1. Dé plek voor IT - ICTscripters
  2. Forum
  3. Scripting & programmeren
  4. PHP + SQL

Forum

  • Herkent deze Notion-structuurscan echte problemen?

    FreelanceAP 6 oktober 2026 om 16:48
  • 🚀 WE ZOEKEN TESTERS! 🚀

    Servertjee 3 oktober 2026 om 10:56
  • Port Father: beta van een browsergame in Antwerpen 1931, feedback welkom

    Syntax 1 oktober 2026 om 11:11
  • Luchtvaartsoftware: Hoe technologie de moderne luchtvaart verandert

    saggy2829 30 september 2026 om 19:31
  • Hoe gebruiken jullie WhatsApp voor marketing en klantopvolging?

    aiqanobzfsej5 29 september 2026 om 12:55
  • [PROJECT] Gamekeuring.nl - Hét onafhankelijke keuringsplatform voor maffiagames & RPG's!

    frio 22 september 2026 om 16:40
  • Ictscripters / Koen

    Aaron 22 september 2026 om 15:07
  • Kweekrijk - van stekje tot Imperium

    Lijno 14 september 2026 om 23:00

Marktplaats

  • Verschillende domeinen te koop (sommige hebben website / content)

    frio 2 oktober 2026 om 14:45
  • 295 Nieuwe Domeinnamen September 2026

    shiga 1 oktober 2026 om 19:09
  • Straatbaas.eu – complete Nederlandstalige en Engelstalige online maffia-RPG

    Jeroen.G 1 oktober 2026 om 17:48

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";
        }
    }
    
    
    ?>
    Meer tonen

    Gegroet :)

    [center]HogwartsCastle[/center]

  • Gast, wil je besparen op je domeinnamen? (ad)
  • 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
    Berichten
    4.479
    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";
        }
    }
    
    
    ?>
    Meer tonen

    [center]HogwartsCastle[/center]

Registratie

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

Nu registreren Aanmelden

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. Privacyverklaring
  10. Contact
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