dongyumiao5210 2015-10-28 23:17
浏览 57
已采纳

如何从数组中提取数据并存储到数据库

EDIT:

I've decided to totally change how I put this to you guys. I'm using the script provided by Amazon to connect to the Alexa API and get some information. I have a table in my database that I'm pulling rows from (by the URL) and using this script to try to update some columns that are currently blank with this gathered information.

The example below is showing the results I get for http://google.com

I hope I've worded this right and haven't been too confusing.

The following code:

public static function parseResponse($response) {
    $xml = new SimpleXMLElement($response,null,false,
                                'http://awis.amazonaws.com/doc/2005-07-11');
    if($xml->count() && $xml->Response->UrlInfoResult->Alexa->count()) {
        $info = $xml->Response->UrlInfoResult->Alexa;
        $nice_array = array(
            'Phone Number'   => $info->ContactInfo->PhoneNumbers->PhoneNumber,
            'Owner Name'     => $info->ContactInfo->OwnerName,
            'Email'          => $info->ContactInfo->Email,
            'Street'         => $info->ContactInfo->PhysicalAddress->Streets->Street,
            'City'           => $info->ContactInfo->PhysicalAddress->City,
            'State'          => $info->ContactInfo->PhysicalAddress->State,
            'Postal Code'    => $info->ContactInfo->PhysicalAddress->PostalCode,
            'Country'        => $info->ContactInfo->PhysicalAddress->Country,
            'Links In Count' => $info->ContentData->LinksInCount,
            'Rank'           => $info->TrafficData->Rank
        );
    }
    echo '<pre>';
    print_r(array_values($nice_array));
    echo '</pre>';
}

Will output this:

Array
(
    [0] => SimpleXMLElement Object
        (
            [0] => unlisted
        )

    [1] => SimpleXMLElement Object
        (
            [0] => aa
        )

    [2] => SimpleXMLElement Object
        (
            [0] => dns-admin@google.com
        )

    [3] => SimpleXMLElement Object
        (
            [0] => aa
        )

    [4] => SimpleXMLElement Object
        (
            [0] => unlisted
        )

    [5] => SimpleXMLElement Object
        (
            [0] => unlisted
        )

    [6] => SimpleXMLElement Object
        (
            [0] => unlisted
        )

    [7] => SimpleXMLElement Object
        (
            [0] => unlisted
        )

    [8] => SimpleXMLElement Object
        (
            [0] => 3555997
        )

    [9] => SimpleXMLElement Object
        (
            [0] => 1
        )

)

As you can see, each of these "objects" correspond to the code above, showing Phone Number, Owner Name, Email, Street, City, State, Postal Code, Country, Links In Count, and Rank, respectively.

What I need to do is take each value and update that row in my database.

  • 写回答

1条回答 默认 最新

  • doupang9080 2015-10-28 23:20
    关注

    Let PHP do the work for you; values or the keys

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler