douxidang9092 2012-03-24 15:35
浏览 63
已采纳

PHP API的XML API! 新开发者,不知道如何做到这一点

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!

  • 写回答

4条回答 默认 最新

  • doupuxuan5784 2012-03-24 15:58
    关注

    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);
                }
    
               }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 Llama如何调用shell或者Python
  • ¥20 eclipse连接sap后代码跑出来空白
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案