Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6216067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:10:03+00:00 2026-05-24T07:10:03+00:00

I am trying to build a mysql query that adds items to a database.

  • 0

I am trying to build a mysql query that adds items to a database. The items are held inside an object that is formatted like:

object(PhealResult)#7 (5) {
  ["request_time"]=>
  string(19) "2011-08-04 14:14:37"
  ["request_time_unixtime"]=>
  int(1312467277)
  ["cached_until"]=>
  string(19) "2011-08-04 20:14:37"
  ["cached_until_unixtime"]=>
  int(1312488877)
  ["_element:private"]=>
  object(PhealElement)#12 (3) {
    ["_name"]=>
    string(6) "result"
    ["_value"]=>
    object(PhealContainer)#11 (1) {
      ["_container:private"]=>
      array(1) {
        ["assets"]=>
        object(PhealRowSet)#14 (3) {
          [0]=>
          object(PhealRowSetRow)#19 (6) {
            ["itemID"]=>
            string(13) "1003152969505"
            ["locationID"]=>
            string(8) "30000157"
            ["typeID"]=>
            string(5) "11489"
            ["quantity"]=>
            string(1) "1"
            ["flag"]=>
            string(1) "0"
            ["singleton"]=>
            string(1) "1"
          }
          [1]=>
          object(PhealRowSetRow)#18 (7) {
            ["itemID"]=>
            string(9) "290900396"
            ["locationID"]=>
            string(8) "66002198"
            ["typeID"]=>
            string(2) "27"
            ["quantity"]=>
            string(1) "1"
            ["flag"]=>
            string(2) "71"
            ["singleton"]=>
            string(1) "1"
            ["contents"]=>
            object(PhealRowSet)#24 (15) {
              [0]=>
              object(PhealRowSetRow)#29 (5) {
                ["itemID"]=>
                string(13) "1003305129036"
                ["typeID"]=>
                string(4) "2183"
                ["quantity"]=>
                string(1) "4"
                ["flag"]=>
                string(3) "117"
                ["singleton"]=>
                string(1) "0"
              }
              **cropped**
            }
          }
          **cropped**
         }
        }
       }
      }

Pay particular attention to how the nesting works. The top level rowset is named “assets”, but then each item in there can have “contents.” Each item in that can also have a “contents” list. There’s a limit to how far it can go in terms of EVE but the limit is unknown and the code should assume there’s no real limit.

I have played around a little with the one of the code snippets located on the http://php.net/manual/en/language.types.array.php which appears to be down as of now.

    function array_value_recursive($key, array $arr){
        $val = null;
        array_walk_recursive($arr, function($v, $k) use($key, &$val){
            $val = $k == $key ? $v : (!is_null($val) ? $val : false);
        });
        return $val;
    }

I cannot seem to wrap my head around how to work with the object / array given that I do not know how deep it goes. How do I know how far in I am and how do I access the data contained when i am x deep in the object/ array. I thank you in advance for your time and assistance.

The code below is the code I was using before I knew that there can be a somewhat endless nested “contents”. I have included this code so you can see what it is that I am trying to accomplish.

try { 
            $corpPheal = new Pheal($fullUserID, $fullAPIKey, "corp");

                $corpAssetList = $corpPheal->AssetList(array('characterID'=>$fullCharID));

                echo "<pre>";
                var_dump($corpAssetList);
                echo "</pre>";


        }
        catch (PhealException $e) {
            echo 'error: ' . $e->code . ' meesage: ' . $e->getMessage();
        }

        $numOfAssetList = count($corpAssetList->assets);


        for ($i =0; $i <= ($numOfAssetList -1); $i++){

            $numOfAssetContents = count($corpAssetList->assets[$i]->contents);
            echo $numOfAssetContents . "<br>\n";

            if ($numOfAssetContents > 0){
                $count = 0;
                for ($j=0; $j <= ($numOfAssetContents - 1); $j++){
                    echo "i = $i, j = $j <br>\n";
                    $count++;
                    foreach ($corpAssetList->assets[$i]->contents[$j] as $key => $value){

                        switch ($key) {
                            case "itemID":
                                $qry = "INSERT INTO eve_asset_list(`itemID`, `typeID`, `quantity`, `flag`, `singleton`) VALUES('$value','";
                                break;

                            case "typeID":
                                $qry = $qry . $value . "','";
                                break;
                            case "quantity":
                                $quantity = $value;
                                $qry = $qry . $value . "','";
                                break;
                            case "flag":
                                $qry = $qry . $value . "','";
                                break;
                            case "singleton":
                                $qry = $qry . $value . "') ON DUPLICATE KEY UPDATE quantity = $quantity";
                                break;
                        }
                    }

                    $result = mysql_query($qry);
                    include "./includes/mysqlError.inc.php";
                }
            }else {

                foreach ($corpAssetList->assets[$i] as $key => $value){

                        switch ($key) {
                            case "itemID":
                                $qry = "INSERT INTO eve_asset_list(`itemID`, `typeID`, `quantity`, `flag`, `singleton`) VALUES('$value','";
                                break;

                            case "typeID":
                                $qry = $qry . $value . "','";
                                break;
                            case "quantity":
                                $quantity = $value;
                                $qry = $qry . $value . "','";
                                break;
                            case "flag":
                                $qry = $qry . $value . "','";
                                break;
                            case "singleton":
                                $qry = $qry . $value . "') ON DUPLICATE KEY UPDATE quantity = $quantity";
                                break;
                        }
                    }

            }
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T07:10:03+00:00Added an answer on May 24, 2026 at 7:10 am

    What your code snippet now does is apply a function to every element array_walk_recursive. This is a predefined function in PHP.

    The function that is applied right now looks whether the current key equals the one that’s given as a parameter. If they’re equal it stores the value and otherwise not.

    Eventually the first found value is returned. This return value can be an array itself and you could use it to access internal data.

    At the moment it doesn’t do anything with the deepness of the data. Is this something that you want to change? If yes, What would you like the function to do?

    Edit:

    You’d probably need something like

    function insert_all($pheal_row_set)
    {
        foreach($pheal_row_set as $pheal_row_set_row)
        {
            foreach($pheal_row_set_row as $key => $value)
            {
                //switch statment
            }
            //insert
            if(!is_null($pheal_row_set_row['contents']) &&
                is_array($pheal_row_set_row['contents']))
            {
                insert_all($pheal_row_set_row['contents']);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to build a MySQL query that uses the rows in a lookup
I'm trying to build a JSON object from a mysql query. The JSON structure
I'm trying to build out a mysql database design for a project. The problem
Using MySQL and PHP; I'm trying to build an index that contains the averages
I am trying to build a page that uses jQuery to call a database
Using PHP and MySQL, I have a forum system I'm trying to build. What
I'm trying to build an active page menu with PHP and MySQL and am
I've been trying to formulate a query to help myself identify resource-heavy queries/database/users using
I'm trying to build a rather specific query to find a set of user_ids
I'm trying to build a Silverlight App that accesses and presents data from a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.