0

我设法创建了一个带有 itemID 和 Item 类型的 mysql 数据库。到目前为止,我所做的只是生成一个按钮,该按钮打开一个指向 eve api 的 url,该 api 从 eve central 获取价格。我目前无法发布图片。

然后,php 代码生成一个 api url 来显示价格,最终我的计划是获取最大购买价格和最小销售价格并对其执行以下操作:如果公司需要该项目,它将是 (maxbuyprice + Minsellprice) /2 如果公司不需要该项目,计算将是 ((maxbuyprice + Minsellprice)/2) * 0.9

我的问题是让 php 解析 xml 而不是显示 xml 文档 - 我这样做是为了调试或查看可用的数据。

例如,我使用 Veldspar 生成的 url 是:使用 Veldspar 生成的 url 是项目名称

index.php 文件:

<?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 文件:

<?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 文件:

<?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';
        }


}

?>
4

2 回答 2

0

在这里,我得到了一些版本,如何帮助我们双方:

$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
于 2013-08-26T12:42:33.047 回答
0

我有点困惑,你想要帮助解析 EVE API xml 还是来自 eve central 的矿物拉 XML?

如果是价格 XML,这就是我使用的,这是在我的主页上...

    // 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];

这是它调用的函数。

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;

}

对于卖出最高价格更改此行...$ItemPrice[$i] = $child->sell->min;

如果你想解析 EVE API,那是一个完全不同的故事,我还没有掌握,因为每个 API XML 都是不同的......

于 2014-01-31T20:14:31.783 回答