View Full Version : Pull data from XML and put in postbit?!
digitalJE5U5
02-03-2003, 02:53 AM
OK, I'm completely lost. But I know this is simple stuff for you guys. I have a Age of Mythology Clan site, and I want to put the users rating into the postbit, under their name.
I think I've found out how to access this rating, which is ever-changing by going here:
http://aom.stats.zone.msn.com/AOM_RC0/query/query.aspx?<?xml version="1.0"?><clr><cmd v="query"/><co g="AOM_RC0" s="100" z="1.0.3"/><qer id="ESO.Query.Example.68.184.73.72" np="0" nn="0" si="0" en="GX_Iron" et="ZS_Human" md="ZS_Lightning" rn="ZS_TopPlayers" tp="ZS_AllTime"/></clr>
In the example above, GX_Iron should be a variable ($post[field5]) . My problem is how do I extract the field (parse?) "primaryrating" from the above resulting XML(link has the XML) and place(print?) it in the postbit?
I've searched everywhere for this, but can't find a simple answer.
Please help.
Thanks,
/DJ
Link14716
02-03-2003, 10:39 AM
$post[field5] should show profile field 5. :)
digitalJE5U5
02-03-2003, 11:27 AM
OK, but what I really need is some php code to place the rating into the postbit.
filburt1
02-03-2003, 12:07 PM
Here are some XML parsing functions if it helps: http://www.php.net/manual/en/ref.xml.php
digitalJE5U5
02-03-2003, 12:25 PM
Ive read that as well as serveral others. Im beginning to understand some of it, but I don' know how to code php. If I had a sample bit of code, I know enough to be able to edit the code, but I certainly cannot write the code from scratch.
to print stuff out on the page in php do
print "whatever will get printed to the page ex: $post[field5]";
digitalJE5U5
02-03-2003, 11:28 PM
ok, but what I want to "print" is in an XML file at that link. How do I take "primary rating" out of the XML file and "print" that?
digitalJE5U5
02-04-2003, 12:38 AM
OK, below is some code that takes the "rating" off that page.
function getmicrotime()
{
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
$starttime = getmicrotime();
$t = time();
$url = "http://aom.stats.zone.msn.com/AOM_RC0/query/query.aspx";
$q = "<?xml%20version=\"1.0\"?><clr><cmd%20v=\"query\"/>";
$q .= "<co%20g=\"AOM_RC0\"%20s=\"100\"%20z=\"1.0.3\"%20t=\"".$t."\"%20U=\"6\"/>";
$q .= "<qer%20id=\"0\"%20np=\"0\"%20nn=\"20\"%20si=\"0\"%20et=\"ZS_Human\"%20md=\"ZS_Supremacy\"%20rn=\"ZS_TopPlayers\"%20tp=\"ZS_AllTime\"/>";
$q .= "</clr>";
$top20 = array();
$rdf = parse_url($url);
$fp = fsockopen($rdf['host'], 80, $errno, $errstr, 30);
if (!$fp) {
echo "Problem loading ESO Stats Data";
return;
}
if ($fp) {
fputs($fp, "GET " . $rdf['path'] . "?" . $q . " HTTP/1.0\r\n");
fputs($fp, "HOST: " . $rdf['host'] . "\r\n\r\n");
$string = "";
$pagetext = "";
while(!feof($fp)) {
$pagetext .= chop(fgetc($fp));
}
fputs($fp,"Connection: close\r\n\r\n");
fclose($fp);
$string = chop($pagetext);
$items = explode("\"",$string);
$lines = count($items);
$offset = 1;
for ($i=23;$i<$lines;$i+=12) {
$top20[$offset]["name"] = $items[$i];
$top20[$offset]["rank"] = $items[$i+2];
$top20[$offset]["rating"] = intval($items[$i+6]);
$offset++;
}
## Hint: Changing the "6" below to a larger number will increase the number of players displayed. Max. = 20 ##
for ($j=1;$j<2;$j++) {
$rating .= $top20[$j]["rating"];
}
}
Maybe that better illustrates what Im trying to do. Now, I did NOT by any means write that code. I found it, and modified it to do what I need.
2 things:
1- What extranious things can I remove from that code, so its more streamlined? Can I 86 the microtime stuff?
2- Where in global.php should I put the finished code, so that I can pull $rating and have it show up wherever I put that variable?
Thanks alot for the help guys.
/DJ
digitalJE5U5
02-09-2003, 08:01 PM
*bump*
Are you trying to do this every post? This is going to slow you down A LOT I would think. Maybe you should make some sort of script to run once a day to grab the rankings and put them in a user field.
digitalJE5U5
02-12-2003, 04:27 AM
That is very good advice. I had not even thought of that. Unfortunately, I don't know how to do any of that.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.