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 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM