These forums have been archived and are now read-only.

The new forums are live and can be found at https://forums.eveonline.com/

EVE Technology Lab

 
  • Topic is locked indefinitely.
 

EVE XML with PHP Help

Author
VH Audaine
Elysiom Corporation
#1 - 2013-12-11 01:23:31 UTC
I am trying to make a php script that pulls corp assets from API and lists them in location - item - type - quantity table format in html table. I got it to the point where it is working except the locationID is listed just once per location rather than per line. Just as it is in the XML pulled from API.

var_dump($assets) shows all XML data is in the array.

Please help to point me in the right direction, where did I go wrong? I think I may have messed up the foreach somehow but I cannot figure it out. I have been at it out for days, thanks a lot for your help in advance!

-VH

Current result:
locationID - itemId - typeID - quantity
xxx - xyx - yxx - xxy
------zxx - xzx - xxz
------yzx - xyz - zyx

yyy - yxz - xyx - yyx
------zzx - xxx - xzz
------yxz - yzz - zzz


Needed result:
locationID - itemId - typeID - quantity
xxx xyx yxx xxy
xxx zxx xzx xxz
xxx yzx xyz zyx

yyy yxz xyx yyx
yyy zzx xxx xzz
yyy yxz yzz zzz


Here is my PHP code:

// Request API from server and create array from returned XML

$keyID="some key";
$vcode="some vcode";
$characterID="some char id";
$url = "https://api.eveonline.com/corp/AssetList.xml.aspx?keyID=".$keyID."&vcode=".$vcode."&characterID=".$characterID."";
//echo ($url);

//Get all assets from API
$data = file_get_contents($url);
$xml = new SimpleXMLElement($data);
$result = $xml -> xpath ('//row[@*] | //rowset/row[@*]');
foreach ($result as $row) {

//Create assocciative array $assets
$assets[] = array ('locationID' => $row['locationID'],
'itemID' => $row['itemID'],
'typeID' => $row['typeID'],
'quantity' => $row['quantity'],
);
}

require_once ($_SERVER["DOCUMENT_ROOT"]."/assetlist_corpassets.html.php");


This is the require_once ($_SERVER["DOCUMENT_ROOT"]."/assetlist_corpassets.html.php"); from above edited to remove html and php tags for this post.

php echo "STATION ID"
php echo "ITEM ID"
php echo "ITEM NAME"
echo "QUANTITY"

foreach ($result as $row)
echo ($row['locationID'])
echo ($row['itemID'])
echo ($row['typeID'])
echo ($row['quantity'])
php endforeach

Steve Ronuken
Fuzzwork Enterprises
Vote Steve Ronuken for CSM
#2 - 2013-12-11 02:53:59 UTC
I'd suggest trying phealng to access the data. handles error conditions and caching for you. Or use Yapeal to load it all into a database for you.


Anyway, that's probably not the problem. Look at the raw XML. You'll find all the items which are inside locations, don't have locations of their own.

Bit more of a pain to work with, I'm afraid.

https://gist.github.com/fuzzysteve/7904434 is something I threw together a while ago. Not how I'd do it now, but it's old code.

Woo! CSM XI!

Fuzzwork Enterprises

Twitter: @fuzzysteve on Twitter

Tripsi Chord
Deep Core Mining Inc.
Caldari State
#3 - 2013-12-11 02:58:17 UTC
Work fine like this (ok ok it's a double loop, but work fine :) )

Quote:
$keyID="xxxxx";
$vcode="xxxxx";
$characterID="xxxx";
$url = "https://api.eveonline.com/corp/AssetList.xml.aspx?keyID=".$keyID."&vcode=".$vcode."&characterID=".$characterID."";

//Get all assets from API
$data = file_get_contents($url);
$xml = new SimpleXMLElement($data);

//Get the Item "container" (eg. POSes)
foreach ($xml->result->rowset->row as $r) {
// Create the array
$assets[] = array ('locationID' => (int) $r['locationID'],
'itemID' => (int) $r['itemID'],
'typeID' => (int) $r['typeID'],
'quantity' => (int) $r['quantity']
);
//GET the contents
foreach($r->rowset->row as $row){
// Push the content in the array
array_push($assets, array ('locationID' => (int) $r['locationID'],
'itemID' => (int) $row['itemID'],
'typeID' => (int) $row['typeID'],
'quantity' => (int) $row['quantity'])
);

}
}

VH Audaine
Elysiom Corporation
#4 - 2013-12-11 03:45:36 UTC
Thanks for fast replies and help with the code, very much. It should give me more than enough to digest over the weekend. Idea

@Steve. I would like to learn the libraries but my current ISP does not allow them. For now until I figure out another ISP I am stuck :)

-VH
Talos Katuma
Helion Production Labs
Independent Operators Consortium
#5 - 2013-12-11 10:32:29 UTC
Using the libraries should not be depending on the isp, it's basically just php code.
Peter Powers
Terrorists of Dimensions
#6 - 2013-12-14 21:41:38 UTC
VH Audaine wrote:
Thanks for fast replies and help with the code, very much. It should give me more than enough to digest over the weekend. Idea

@Steve. I would like to learn the libraries but my current ISP does not allow them. For now until I figure out another ISP I am stuck :)

-VH

PhealNG should be able to run wherever your other code is running as well.

3rdPartyEve.net - your catalogue for 3rd party applications

VH Audaine
Elysiom Corporation
#7 - 2013-12-25 06:20:34 UTC  |  Edited by: VH Audaine
If I may...need a bit more help. I am on the next part of the project now. This one is with Eve-Central. Here is the code below. I am stuck at the point where I cannot figure out how to join the type ids to the actual names to the individual type ids printed out in real names, if that makes sense lol. This code works except there are no real names of the types that print. array_merge did not seem to help as I was not able to iterate through $merged_array correctly.

@Steve. Your article was a starting point. Thanks, that was great!. https://www.fuzzwork.co.uk/2013/05/06/using-the-eve-central-api-with-php/

Thanks for any help guys and Merry Xmas!


$type = array(18, 19, 20, 21, 34, 35, 36, 37, 38, 39, 40,
1223, 1224, 1225, 1226, 1227, 1228, 1229, 1230, 1231, 1232,
17425, 17426, 17428, 17429, 17432, 17433, 17436, 17437, 17440,
17441, 17444, 17445, 17448, 17449, 17452, 17453, 17455, 17456,
17459, 17460, 17463, 17464, 17466, 17467, 17470, 17471,
17865, 17866, 17867, 17868, 17869, 17870, 11396, 11399);


$url="http://api.eve-central.com/api/marketstat?regionlimit=10000032&typeid=".join('&typeid=',$type);
$data=file_get_contents($url);
$xml = simplexml_load_string($data);

foreach($xml->marketstat->type as $d) {
$prices[] = array (' 'sellavgap' => $d->sell->avg,
'sellmaxap' => $d->sell->max,
'sellminap' => $d->sell->min,
'buyavgap' => $d->buy->avg,
'buymaxap' => $d->buy->max,
'buyminap' => $d->buy->min,
);

foreach($d as $n) { //I realize this is wrong. I suppose this is where I got stuck from.
$names[] =array('Plagioclase' => $n['Plagioclase'],
'Spodumain' =>$n['Spodumaain'],
'Kernite' =>$n['Kernite'],
'Hedbergite' =>$n['Hedbergite'],
'Tritanium' =>$n['Tritanium'],);


echo "ORE NAME"
echo "SELL AVERAGE"
echo "SELL MAXIMUM"
echo "SELL MINIMUM"
echo "BUY AVERAGE"
echo "BUY MAXIMUM"
echo "BUY MINIMUM"

php foreach($prices as $k => $v):

echo ($names);
echo ($v['sellavgap'])
echo ($v['sellmaxap'])
echo ($v['sellminap'])
echo ($v['buyavgap'])
echo ($v['buymaxap'])
echo ($v['buyminap'])

php endforeach
Steve Ronuken
Fuzzwork Enterprises
Vote Steve Ronuken for CSM
#8 - 2013-12-25 21:11:44 UTC
VH Audaine wrote:
If I may...need a bit more help. I am on the next part of the project now. This one is with Eve-Central. Here is the code below. I am stuck at the point where I cannot figure out how to join the type ids to the actual names to the individual type ids printed out in real names, if that makes sense lol.





I'd point to the place where I'm using the xpath in that example.

You can't be sure the order that the values are coming back from eve central (it'll probably be the same each time, but depending on that is a little risky)

Iterate through the result set you've got from eve central, using an xpath query for each typeid. That way, you know exactly which type you're working with, and you can just hardcode an array of typeid=>typename, which you can then use to resolve the typeids.

Alternatively, pull the id attribute from $d, so you can use that as the key to fill in, in your $prices array. (and later, when iterating through it, it'll show up as $key, so you can use a hardcoded array to go to the name) $d->attributes()->id will give you the one you're processing at that time. set $prices[ $d->attributes()->id]=array(stuff);

Woo! CSM XI!

Fuzzwork Enterprises

Twitter: @fuzzysteve on Twitter

VH Audaine
Elysiom Corporation
#9 - 2013-12-26 22:57:57 UTC
Thanks! Got it working.
-VH