<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<?php
//TRITANIUM
$curl = curl_init();
curl_setopt ($curl, CURLOPT_URL, 'http://api.eve-central.com/api/marketstat?typeid=34&usesystem=30002510');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec ($curl);
if ($result === false)
{
die('Error fetching data: ' . curl_error($curl));
}
curl_close ($curl);
//END
$xml = simplexml_load_string($result);
if ($xml === false)
{
die('Error parsing XML');
}
//now we can loop through the xml structure
echo "<font family='courier new' font size='24' font color='red'>RENS</font>";
echo "<font family='times new roman'>";
echo "<table border ='0' cellpadding='6'>";
echo "<tr>";
echo "<td>";
foreach ($xml->marketstat->type as $item)
{
echo "Tritanium<br>";
echo "Buy: $" . $item->buy->max;
echo "<br>Sell: $" . $item->sell->min; break;
}
echo "</td>";
echo "</tr>";
?>
</body>
</html>
That works fine, nothing wrong with it and here is the XML of the external webpage:
<evec_api method="marketstat_xml" version="2.0"> <marketstat> <type id="34"> <buy> <volume>1794383200</volume> <avg>5.11</avg> <max>5.52</max> <min>2.81</min> <stddev>0.78</stddev> <median>5.29</median> <percentile>5.52</percentile> </buy> <sell> <volume>1294276483</volume> <avg>5.97</avg> <max>12.00</max> <min>5.67</min> <stddev>1.15</stddev> <median>5.99</median> <percentile>5.68</percentile> </sell> <all> <volume>3088659683</volume> <avg>5.47</avg> <max>12.00</max> <min>2.81</min> <stddev>1.19</stddev> <median>5.51</median> <percentile>3.46</percentile> </all> </type> </marketstat> </evec_api>
Now when I try to do something like this:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<?php
$curl = curl_init();
curl_setopt ($curl, CURLOPT_URL, 'http://api.eve-central.com/api/marketstat?typeid=34&typeid=35&usesystem=30002510');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec ($curl);
if ($result === false)
{
die('Error fetching data: ' . curl_error($curl));
}
curl_close ($curl);
$xml = simplexml_load_string($result);
if ($xml === false)
{
die('Error parsing XML');
}
//now we can loop through the xml structure
echo "<font family='courier new' font size='24' font color='red'>RENS</font>";
echo "<font family='times new roman'>";
echo "<table border ='0' cellpadding='6'>";
foreach ($xml->marketstat->type as $item)
{
switch($item)
{
case '34':
{
echo "Tritanium<br>";
echo "Buy: $" . $item->buy->max;
echo "<br>Sell: $" . $item->sell->min; break;
}
case 35:
{
echo "Pyerite<br>";
echo "Buy: $" . $item->buy->max;
echo "<br>Sell: $" . $item->sell->min; break;
}
}
}
?>
</body>
</html>
and the XML feed:
<evec_api method="marketstat_xml" version="2.0"> <marketstat> <type id="34"> <buy> <volume>1874383200</volume> <avg>5.13</avg> <max>5.53</max> <min>2.81</min> <stddev>0.76</stddev> <median>5.35</median> <percentile>5.52</percentile> </buy> <sell> <volume>1291450819</volume> <avg>5.97</avg> <max>12.00</max> <min>5.68</min> <stddev>1.16</stddev> <median>5.99</median> <percentile>5.68</percentile> </sell> <all> <volume>3165834019</volume> <avg>5.47</avg> <max>12.00</max> <min>2.81</min> <stddev>1.19</stddev> <median>5.52</median> <percentile>3.46</percentile> </all> </type> <type id="35"> <buy> <volume>988942430</volume> <avg>12.56</avg> <max>13.12</max> <min>9.00</min> <stddev>1.43</stddev> <median>13.06</median> <percentile>13.12</percentile> </buy> <sell> <volume>326509596</volume> <avg>15.11</avg> <max>15.29</max> <min>13.75</min> <stddev>0.43</stddev> <median>15.29</median> <percentile>13.98</percentile> </sell> <all> <volume>1330452026</volume> <avg>13.09</avg> <max>15.29</max> <min>4.00</min> <stddev>2.38</stddev> <median>13.11</median> <percentile>8.29</percentile> </all> </type> </marketstat> </evec_api>
Now I need to be able to loop through the different type IDs but I have no idea how to do that, as you can tell I've tried a couple different ways but none of them work. The problem is I don't know how to access the ID number in this snippet from the xml feed:
<type id="34">
How would I be able to access that number and loop through it when there are multiple type ids?
This post has been edited by kiasta: 21 January 2013 - 10:23 AM

New Topic/Question
Reply


MultiQuote


|