2013-08-25 63 views
0

我設法創建了一個帶有itemID和Item類型的mysql數據庫。到目前爲止,我所能做的就是生成一個按鈕,打開一個網址,以便抓住前夕中央的價格。我目前無法發佈圖片。Eve API xml到php

然後php代碼會生成一個api url來顯示最終我的計劃是抓住最大買入價格和最小賣出價格的價格,並對它們執行以下操作: 如果公司需要它的項目(maxbuyprice + Minsellprice)/ 2 如果CORP不需要的項目計算爲((maxbuyprice + Minsellprice)/ 2)* 0.9

我的問題就是如何讓PHP的解析XML,而不是顯示XML文檔 - 我這樣做是爲了調試或查看可用的數據。

爲例,我與Veldspar生成的URL是: generated url using Veldspar is the item name

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


} 

?> 

回答

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 
0

林有點彷徨,你想幫助解析EVE API XML或從除夕中央礦物拉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] = $兒童安全> sell->分鐘;

如果你想分析EVE API,這是一個完全不同的故事,我還沒有掌握,因爲每個API XML是不同的...