PHP row

Gestart doorShahiem4 reacties33 weergaven

5 berichten · pagina 1 van 1

Shahiem

Lid · Topicstarter

Berichten
20.364
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
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?

Code

[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/include"]include[/URL] [COLOR= #DD0000]../includes/config.php[/COLOR][COLOR= #007700];[/COLOR]
[COLOR= #FF8000]// Load the XML data from the specified file name.  
// The second argument (NULL) allows us to specify additional libxml parameters,
// we dont need this so well 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.[/COLOR]
[COLOR= #0000BB]$pFile[/COLOR] [COLOR= #007700]= new[/COLOR] SimpleXMLElement[COLOR= #007700]([/COLOR][COLOR= #DD0000]http://hardsoftware.nl/xml/elektrokoopjes.xml[/COLOR][COLOR= #007700],[/COLOR] null[COLOR= #007700],[/COLOR] true[COLOR= #007700]);[/COLOR]
[COLOR= #FF8000]// Now that weve 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[/COLOR]

[URL="http://www.php.net/foreach"]foreach[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$pFile[/COLOR][COLOR= #007700]->[/COLOR]item [COLOR= #007700]as[/COLOR] [COLOR= #0000BB]$pChild[/COLOR][COLOR= #007700])
{[/COLOR]    
    [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"INSERT INTO
                       merken
                    (
                        merk_naam
                    ) VALUES (
                        "[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$core[/COLOR][COLOR= #007700]->[/COLOR]mysql[COLOR= #007700]->[/COLOR]escape[COLOR= #007700]([/COLOR][URL="http://www.php.net/stripslashes"]stripslashes[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$pChild[/COLOR][COLOR= #007700]->[/COLOR]brand[COLOR= #007700])).[/COLOR][COLOR= #DD0000]"
                                                                                                    
                    )"[/COLOR][COLOR= #007700])[/COLOR] or [URL="http://www.php.net/die"]die[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]());[/COLOR]
    [COLOR= #0000BB]$merk[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$core[/COLOR][COLOR= #007700]->[/COLOR]mysql[COLOR= #007700]->[/COLOR]query[COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT
                                        *
                                FROM
                                    merken
                                WHERE
                                    merk_naam = "[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$core[/COLOR][COLOR= #007700]->[/COLOR]mysql[COLOR= #007700]->[/COLOR]escape[COLOR= #007700]([/COLOR][URL="http://www.php.net/stripslashes"]stripslashes[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$pChild[/COLOR][COLOR= #007700]->[/COLOR]brand[COLOR= #007700])).[/COLOR][COLOR= #DD0000]""[/COLOR][COLOR= #007700]);[/COLOR]
    [COLOR= #0000BB]$merkf[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$core[/COLOR][COLOR= #007700]->[/COLOR]mysql[COLOR= #007700]->[/COLOR]fetch[COLOR= #007700]([/COLOR][COLOR= #0000BB]$merk[/COLOR][COLOR= #007700]);[/COLOR]
  
        
                    
    [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"INSERT INTO
                        producten
                    (
                        naam,
                        link,
                        beschrijving,
                        prijs,
                        cat,
                        afbeelding_groot,
                        daisycon_id,
                        subcat,
                        subsubcat,
                        merk_product
                    ) VALUES (
                        "[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$core[/COLOR][COLOR= #007700]->[/COLOR]mysql[COLOR= #007700]->[/COLOR]escape[COLOR= #007700]([/COLOR][URL="http://www.php.net/stripslashes"]stripslashes[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$pChild[/COLOR][COLOR= #007700]->[/COLOR]title[COLOR= #007700])).[/COLOR][COLOR= #DD0000]",
                        "[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$core[/COLOR][COLOR= #007700]->[/COLOR]mysql[COLOR= #007700]->[/COLOR]escape[COLOR= #007700]([/COLOR][URL="http://www.php.net/stripslashes"]stripslashes[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$pChild[/COLOR][COLOR= #007700]->[/COLOR][URL="http://www.php.net/link"]link[/URL][COLOR= #007700])).[/COLOR][COLOR= #DD0000]",
                        "[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$core[/COLOR][COLOR= #007700]->[/COLOR]mysql[COLOR= #007700]->[/COLOR]escape[COLOR= #007700]([/COLOR][URL="http://www.php.net/stripslashes"]stripslashes[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$pChild[/COLOR][COLOR= #007700]->[/COLOR]description[COLOR= #007700])).[/COLOR][COLOR= #DD0000]",
                        "[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$pChild[/COLOR][COLOR= #007700]->[/COLOR]minimum_price[COLOR= #007700].[/COLOR][COLOR= #DD0000]",   
                        "[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$core[/COLOR][COLOR= #007700]->[/COLOR]mysql[COLOR= #007700]->[/COLOR]escape[COLOR= #007700]([/COLOR][URL="http://www.php.net/stripslashes"]stripslashes[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$pChild[/COLOR][COLOR= #007700]->[/COLOR]category[COLOR= #007700])).[/COLOR][COLOR= #DD0000]",
                        "[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$pChild[/COLOR][COLOR= #007700]->[/COLOR]img_medium[COLOR= #007700].[/COLOR][COLOR= #DD0000]", 
                        "[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$pChild[/COLOR][COLOR= #007700]->[/COLOR]daisycon_unique_id[COLOR= #007700].[/COLOR][COLOR= #DD0000]",
                         "[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$core[/COLOR][COLOR= #007700]->[/COLOR]mysql[COLOR= #007700]->[/COLOR]escape[COLOR= #007700]([/COLOR][URL="http://www.php.net/stripslashes"]stripslashes[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$pChild[/COLOR][COLOR= #007700]->[/COLOR]sub_sub_category[COLOR= #007700])).[/COLOR][COLOR= #DD0000]",
                         "[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$core[/COLOR][COLOR= #007700]->[/COLOR]mysql[COLOR= #007700]->[/COLOR]escape[COLOR= #007700]([/COLOR][URL="http://www.php.net/stripslashes"]stripslashes[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$pChild[/COLOR][COLOR= #007700]->[/COLOR]sub_category[COLOR= #007700])).[/COLOR][COLOR= #DD0000]",
                         "[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$merkf[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]id[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000]"                                                                                 
                    )"[/COLOR][COLOR= #007700])[/COLOR] or [URL="http://www.php.net/die"]die[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]());[/COLOR]
 
                
    [COLOR= #FF8000]// Print our channel specific information, this should be
    // easy to understand, basically were grabbing the 
    // title, descripting and link nodes and outputting their values[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"<h1>"[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$pChild[/COLOR][COLOR= #007700]->[/COLOR]title [COLOR= #007700].[/COLOR] [COLOR= #DD0000]"</h1>
"[/COLOR][COLOR= #007700];[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"IMG: "[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$pChild[/COLOR][COLOR= #007700]->[/COLOR]category[COLOR= #007700].[/COLOR][COLOR= #DD0000]" en sub "[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$pChild[/COLOR][COLOR= #007700]->[/COLOR]sub_category[COLOR= #007700].[/COLOR][COLOR= #DD0000]"<p>
"[/COLOR][COLOR= #007700];[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$pChild[/COLOR][COLOR= #007700]->[/COLOR]description [COLOR= #007700].[/COLOR] [COLOR= #DD0000]"<br />
"[/COLOR][COLOR= #007700];[/COLOR]
    [URL="http://www.php.net/printf"]printf[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]Visit us at <a href="%s">%s</a><br />[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #DD0000]"
"[/COLOR][COLOR= #007700],[/COLOR]  [COLOR= #0000BB]$pChild[/COLOR][COLOR= #007700]->[/COLOR][URL="http://www.php.net/link"]link[/URL][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$pChild[/COLOR][COLOR= #007700]->[/COLOR][URL="http://www.php.net/link"]link[/URL][COLOR= #007700]);[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"</p>
"[/COLOR][COLOR= #007700];[/COLOR]
    
    [COLOR= #FF8000]// Now we want to loop through the items inside this channel[/COLOR]
    [URL="http://www.php.net/foreach"]foreach[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$pFile[/COLOR][COLOR= #007700]->[/COLOR]general[COLOR= #007700]->[/COLOR]item [COLOR= #007700]as[/COLOR] [COLOR= #0000BB]$pItem[/COLOR][COLOR= #007700])
    {[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"<p>
"[/COLOR][COLOR= #007700];[/COLOR]
        
        [COLOR= #FF8000]// If this item has child nodes as it should, 
        // loop through them and print out the data[/COLOR]
        [URL="http://www.php.net/foreach"]foreach[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$pItem[/COLOR][COLOR= #007700]->[/COLOR]general[COLOR= #007700]() as[/COLOR] [COLOR= #0000BB]$pChild[/COLOR][COLOR= #007700])
        {[/COLOR]
            [COLOR= #FF8000]// 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[/COLOR]
            [URL="http://www.php.net/switch"]switch[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$pChild[/COLOR][COLOR= #007700]->[/COLOR]getName[COLOR= #007700]())
            {
                case[/COLOR] [COLOR= #DD0000]title[/COLOR][COLOR= #007700]:[/COLOR]
                    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"<b>$pChild</b><br />
"[/COLOR][COLOR= #007700];[/COLOR]
                    [URL="http://www.php.net/break"]break[/URL][COLOR= #007700];
                    
                case[/COLOR] [COLOR= #DD0000]link[/COLOR][COLOR= #007700]:[/COLOR]
                    [URL="http://www.php.net/printf"]printf[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]<a href="%s>%s</a><br />[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #DD0000]"
"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$pChild[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$pChild[/COLOR][COLOR= #007700]);[/COLOR]
                    [URL="http://www.php.net/break"]break[/URL][COLOR= #007700];
                    
                default:[/COLOR]
                    [URL="http://www.php.net/echo"]echo[/URL] [URL="http://www.php.net/nl2br"]nl2br[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$pChild[/COLOR][COLOR= #007700]) .[/COLOR] [COLOR= #DD0000]"<br />
"[/COLOR][COLOR= #007700];[/COLOR]
                    [URL="http://www.php.net/break"]break[/URL][COLOR= #007700];
            }
        }[/COLOR]
        
        [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"</p>
"[/COLOR][COLOR= #007700];
    }
}[/COLOR]

?>


Gegroet smile
0
Berichten
5.957
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Die kolom unique maken.
0
Shahiem

Lid · Topicstarter

Berichten
20.364
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
En hoe doe ik dat? smile
0
Berichten
5.957
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
In phpmyadmin is er zon knopje, normaal doe je dat met de kolom id ook.
0
Shahiem

Lid · Topicstarter

Berichten
20.364
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Het werkt wel maar hij voegt maar 3 merken toe yummie
0

Jouw reactie

Deel je idee, stel een vraag of help een ander verder.

Editor laden…

Praat mee met de One2xs-community.

Inloggen om te reageren