Php – XML API to PHP! New developer, no idea how to do this

apiparsingphpxml

Simple question, I should think. Unfortunately, I couldn't figure out how to get it working.

I have an xml data sheet that looks like this:

<leads>
    <leadDetails>
        <lead_id>3886961</lead_id>
        <campaign_id>1173</campaign_id>
        <campaign_name>Tesco vs Argos - Submit (UK)</campaign_name>
        <subID>N/A</subID>
        <gateway>yes</gateway>
        <ip>109.155.249.140</ip>
        <referring_url>http://adworkmedia.com/gTemplate.php?GID=1514&pubID=2312&sid=&ST=
        </referring_url>
        <date>2012-03-24 07:19:07</date>
        <payout>$0.70</payout>
        <status>Credited</status>
    </leadDetails>
</leads>

I should add that this XML sheet is not hosting on my servers, but is dynamically updated as I get a new lead, by my network. Feel free to ask me more questions if needed.

MY QUESTION IS: How can I write a code that reads the XML page, and uploads, for each , the date, the IP, and the campaign_name to a mySQL table.

Thanks!

Best Solution

Hi.

           if( $xml = simplexml_load_file("the_url_of_xml"))
            {
              foreach($xml->leads->leadDetails as $detail) 
              {   
                $camp_id = $detail->campaign_id;
                $camp_name = $detail->campaign_name;
                $sql = "INSERT INTO myTable (id,name) VALUES ('$camp_id','$camp_name')";//AND so on
                mysql_query($sql);
            }

           }