Jump to content

XML and pulling data to insert into DB


jacko_162

Recommended Posts

FOr some reason i cant pull data from an XML file to insert into the database, it works without error just adds a blank value in the database?

 

i have this code at the moment, i guess arrayValue[71] is the value i need to pull and add to the "TABLE2" table, but when i run the script it just adds a blank value in the database?

 

<?php
include "connect.php";

//Price check Isle 9001! Query EVE-Central API. Example XML file is: http://api.eve-central.com/api/marketstat?typeid=35&regionlimit=10000002
$queryItemList = mysql_query("SELECT * FROM TABLE2;") or die(mysql_error());
$rowCount = mysql_num_rows($queryItemList);
$s=0;
$typeArray = array();
$region = "regionlimit=10000002";
while($s<$rowCount){
$typeID = mysql_result($queryItemList,$s,"typeID");
echo $typeID."<br />";

//echo "start<br />";
$reader = new XMLReader();
//echo "initialized XMLReader<br />";
$url = "http://api.eve-central.com/api/marketstat?typeid=".$typeID;
echo $url.$region."<br />";
$reader->open($url.'&'.$region);
$t=0;
$arrayName = array();
$arrayValue	 = array();
while ($reader->read()) {
	//echo $reader->name;
	$name = $reader->name;
	$arrayName[$t] = $name;
	if ($reader->hasValue) {
		//echo ": " . $reader->value."<br />";
		$value = $reader->value;
		$arrayValue[$t] = $value;
	}

	$t++;
}
echo $arrayValue[71];
$import="UPDATE TABLE2 SET marketPrice='$arrayValue[71]' WHERE typeID='$typeID';";
mysql_query($import) or die(mysql_error());
$s++;;
}
print_r($typeArray);

/*print_r($arrayName);
echo "<br />";
echo "<br />";
echo "<br />";
print_r($arrayValue);*/

?>

 

an example XML file would be:

<!--
Automatically generated data from EVE-Central.com 
-->
<!-- This is the new API :-) -->
−
<evec_api version="2.0" method="marketstat_xml">
−
<marketstat>
−
<type id="24692">
−
<all>
<volume>4.00</volume>
<avg>152500000.00</avg>
<max>152500000.00</max>
<min>152500000.00</min>
<stddev>0.00</stddev>
<median>152500000.00</median>
<percentile>0.00</percentile>
</all>
−
<buy>
<volume>0.00</volume>
<avg>0.00</avg>
<max>0.00</max>
<min>0.00</min>
<stddev>0.00</stddev>
<median>0.00</median>
<percentile>0.00</percentile>
</buy>
−
<sell>
<volume>4.00</volume>
<avg>152500000.00</avg>
<max>152500000.00</max>
<min>152500000.00</min>
<stddev>0.00</stddev>
<median>152500000.00</median>
<percentile>152500000.00</percentile>
</sell>
</type>
</marketstat>
</evec_api>

 

im looking at pulling the following value from the <sell> section:

<median>152500000.00</median>

 

i am guessing the above should be arrayValue[71] but for some reason its not picking it up.

 

any help on this would be greatly appreciated as im lost in this script.

Link to comment
Share on other sites

try this trick

$import="UPDATE TABLE2 SET marketPrice='$arrayValue[71]' WHERE typeID='$typeID';";
echo $import.'<br />';

 

this will give you query in your browser copy and execute it on console and execute if this query executed successfully then your code is fine else you get some error then by seeing the error you can easily debug it.

Link to comment
Share on other sites

  • 2 months later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.