0

I have managed to create a mysql database with itemIDs and Item types. so far all I have managed to do is generate a button that opens a url to eve api that grabs the prices from eve central. I can't currently post images.

The php code then generates an api url to show the prices which eventually my plan is to grab the Max Buy Prices and Min sell prices and perform on of the following on them: if the corp needs the item it will be (maxbuyprice + Minsellprice)/2 if the corp doesn't need the item the calculation will be ((maxbuyprice + Minsellprice)/2) * 0.9

My problem is getting php to parse the xml instead of showing the xml document - I did this for debugging or seeing the data that is available.

for an example the url that I generated with Veldspar is: generated url using Veldspar is the item name

index.php file:

<?php
include_once $_SERVER['DOCUMENT_ROOT'] .'/includes/db.inc.php';
$pagetitle = 'HoMs Asset Management System - Create Contract';
$pagedescription = 'HoMs Asset Management System for managing Corporation Contracts and Pricing';
include_once $_SERVER['DOCUMENT_ROOT'] .'/includes/access.inc.php';

include_once $_SERVER['DOCUMENT_ROOT'] .'/includes/ObjectClasses.inc.php';
include_once $_SERVER['DOCUMENT_ROOT'] .'/includes/helpers.inc.php';
include_once $_SERVER['DOCUMENT_ROOT'] .'/includes/EveCentral.inc.php';


if (isset($_POST['action']) and $_POST['action']=='View Eve Central Prices')

 {
    $itemname = html($_POST['ItemName']);
    calculateAskingPrice($itemname);

}


include 'createcontract.html.php';
?>

db.inc.php file:

<?php
//local dbstrings
//production dbstrings
$dbhost='localhost';
$dbusername='homedata1';
$dbpassword='EzPKfmxcTKAeSnDs';
$dbname='homdata';

Function connect2db()
{
    Global $dbhost;
    Global $pagetitle;
    Global $pagedescription;
    Global $mysqlport;
    Global $dbname;
    Global $dbusername;
    Global $dbpassword;
    Global $pdo;
    Global $error;
    Global $curNewsMessage;
    Global $logged;
    Global $ItemList;
    try
        {
            $pdo = new PDO('mysql:host=' .$dbhost .';dbname=' .$dbname .';port=' .$mysqlport, $dbusername, $dbpassword);
            $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            $pdo->exec('SET NAMES "utf8"');
        return TRUE;

        }
    catch (PDOException $dbconerr)
        {
            $pagetitle = 'Hom Asset Management - Database Connection Error';
            $pagedescription = 'There was a problem connecting to the database';
            $error = 'Unable to connect to the database server:' ."\n\n"
            .'The database in which this pages content relies on is unavailable or, for other reasons is not contactable' ."\n"
            .'I am liasing with my website host to get this resolved as quickly as possible. Please check later.' ."\n"
            .'sorry for any inconvenience' ."\n\n" .'This information may help to diagnose the problem: <br>' .$dbconerr;
            $logged = 'Sorry. The interactive areas are unavailable because the database is unavailable';
            $curNewsMessage = 'News message unavailable. ' ."\n" .' Database connection error';
            return FALSE;
        }

return TRUE;

}

EveCentral.inc.php file:

<?php

include_once $_SERVER['DOCUMENT_ROOT'] .'/includes/helpers.inc.php';
function calculateAskingPrice($Item)
{
// Connect to the database and search for the item posted
include_once $_SERVER['DOCUMENT_ROOT'] .'/includes/db.inc.php';
Global $pdo;
Global $itemname;


        if (connect2db())
        {
            $sql = "SELECT * FROM `itemtypes` WHERE ItemName=:itemname";
            $s = $pdo->Prepare($sql);
            $s->bindValue(':itemname',$Item);
            $s->execute();

            $row = $s->fetch();
            if ($row > 0)
            {
            $itemid = html($row['ID']);
            $evecurl = 'http://api.eve-central.com/api/marketstat?typeid=' .$itemid .'&usesystem=30000142';
            header('Location: ' .$evecurl);
            }

            else
            htmlout('Item not found: ' . $itemname);

        }

        else
        {
            echo 'problem connecting to database';
        }


}

?>
hakre
  • 193,403
  • 52
  • 435
  • 836
timmac15
  • 59
  • 3

2 Answers2

0

here i got some version how can help us both:

$xml = simplexml_load_file('http://api.eve-central.com/api/marketstat?usesystem=30000142&hours=24&typeid=3683&minQ=10000');

echo $xml->marketstat->type->sell->min; // 257.99
0

Im a little comfused, are you wanting help parsing the EVE API xml or the mineral pull XML from eve central?

If it is the price XML, here is what i use, this is on my main page...

    // Get Mineral Prices
GetCurrentMineralPrice();
$TritPrice = $ItemPrice[1];
$PyerPrice = $ItemPrice[2];
$MexPrice = $ItemPrice[3];
$IsoPrice = $ItemPrice[4];
$NocxPrice = $ItemPrice[5];
$ZydPrice = $ItemPrice[6];
$MegaPrice = $ItemPrice[7];
$MorPrice = $ItemPrice[8];

and this is the function it calls.

function GetCurrentMineralPrice() {

global $ItemPrice;

$xml = simplexml_load_file("http://api.eve-central.com/api/marketstat?typeid=34&typeid=35&typeid=36&typeid=37&typeid=38&typeid=39&typeid=40&typeid=11399&usesystem=30000142");
$i = 1;

foreach ($xml->marketstat->type as $child) {

    $ItemPrice[$i] = $child->buy->max;
    $i++;

}

return $ItemPrice;

}

For the sell max price change this line...$ItemPrice[$i] = $child->sell->min;

if you are wanting to parse the EVE API, thats an entirely different story, that I havent mastered yet since each API XML is different...

Curtis
  • 1
  • 2