1

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.

jddev2381
  • 55
  • 7
  • So you want the array's keys or the values of the array? –  Oct 29 '15 at 01:00
  • I'm thinking I will need each to do what I want. I want to store each value in a separate column within the database. For instance, I have a column for each - "Phone number, owner name, email, street, etc....." I need to extract the values of each of those and store in the database. – jddev2381 Oct 29 '15 at 01:21
  • Possible duplicate of [Insert array into MySQL database with PHP](http://stackoverflow.com/questions/10054633/insert-array-into-mysql-database-with-php) –  Oct 29 '15 at 01:29
  • I've edited my question above. I don't believe it is a duplicate but it could be my (mis)understanding of PHP that leads me to believe this. ;) – jddev2381 Oct 29 '15 at 03:36
  • Your question's not an exact duplicate but it's close. Your for loop(that you removed) does the job of the implode on the top answer of that question. You just need a variable that you append the column names to. And another one for the values. Possibly a 3rd if you're using g prepared statements. Don't forget to escape values if not using prepared statements. –  Oct 29 '15 at 03:47
  • 1
    Why dont you show us a query youve tried at this point and we will assist in making it useful. – Kirk Logan Oct 29 '15 at 04:04
  • I don't have a query to share with you @KirkLogan I haven't written a query because I can't extract the values of the arrays to write a query. – jddev2381 Oct 29 '15 at 19:09
  • This is fit for a Google search not a question. Try something. Then we can help. – Kirk Logan Oct 29 '15 at 19:57
  • @KirkLogan I had searched Google at that point and was not finding anything. Thanks for the tip though! ;) – jddev2381 Jan 26 '16 at 17:21

1 Answers1

0

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

jas-
  • 1,801
  • 1
  • 18
  • 30