You are here:  » AFL - Database


AFL - Database

Submitted by russellharrower on Fri, 2009-05-01 16:09 in

Hey,
I am wanting to know, i have this xml page http://xml.afl.com.au/expandablegamebar.aspx?roundid=710

and i would like to do the following.
I would like somehow to know who the winner of the round of each game is and for it to give me the team name of the winner.

For e.g

AWAY
AWAY-ID 38
AWAY-STATSID 40
AWAY-REF COLL
AWAY-NAME Collingwood
AWAY-NICK Magpies
AWAY-JERSEY 1
AWAY-SCORE 127
AWAY-GOALS 19
AWAY-SUPERGOALS
AWAY-BEHINDS 13
HOME
HOME-ID 45
HOME-STATSID 100
HOME-REF NMFC
HOME-NAME North Melbourne
HOME-NICK Kangaroos
HOME-JERSEY 1
HOME-SCORE 75

As you can see the home team only scored 75 while collingwood scored 127, is there a PHP script that will tell me which team one?

Thanks

Submitted by support on Fri, 2009-05-01 16:22

Hello Russell,

Sure - first of all, I think you know from the demo the correct Format String to use for this XML:

xml|ROUNDS/R/M/

And from there, within your myRecordHandler function, it is just a case of comparing $record["HOME-SCORE"] with $record["AWAY-SCORE"], for example:

function myRecordHandler($record)
{
  if ($record["AWAY-SCORE"] > $record["HOME-SCORE"])
  {
    print $record["AWAY-NAME"]." win!";
  }
  elseif($record["AWAY-SCORE"] < $record["HOME-SCORE"])
  {
    print $record["HOME-NAME"]." win!";
  }
  else
  {
    print "Draw";
  }
}

Hope this helps!
Cheers,
David.

Submitted by russellharrower on Sat, 2009-05-02 05:36

the only issue i have with
xml|ROUNDS/R/M/
is i cant get the round number.
as that is in the
xml|ROUNDS/

Would i have to run
xml|ROUNDS/R/M/
&
xml|ROUNDS/

Submitted by russellharrower on Sat, 2009-05-02 05:53

That helps however i cant get the round number for e.g that RSS feed is for round 6.

This is what i am having to do to get the round number there must be an easyer way?

<?php
  
require("MagicParser.php");
  
$filename "http://xml.afl.com.au/expandablegamebar.aspx?roundid=710";
function 
myRecordHandler($record)
{
  if (
$record["AWAY-SCORE"] > $record["HOME-SCORE"])
  {
    print 
$round." - ";
    print 
$record["AWAY-NAME"]." win!";
  }
  elseif(
$record["AWAY-SCORE"] < $record["HOME-SCORE"])
  {
    print 
$record["HOME-NAME"]." win!";
  }
  else
  {
    print 
"Draw";
  }
  echo 
"<br/>";
}
function 
myRecord($round)
{
$round $round["R-ORD"];
}
  
MagicParser_parse($filename,"myRecord","xml|ROUNDS/");
  
MagicParser_parse($filename,"myRecordHandler","xml|ROUNDS/R/M/");
?>

Submitted by russellharrower on Sat, 2009-05-02 06:27

how do i get the round ID.

I have had to do this to get it the round ID - ROUND NO.

but the $roundNo does not work.

<?php
  require("MagicParser.php");
  $filename = "http://xml.afl.com.au/expandablegamebar.aspx?roundid=710";
function myRecordHandler($record)
{
  if ($record["AWAY-SCORE"] > $record["HOME-SCORE"])
  {
    print $roundNo." - ";
    print $record["AWAY-NAME"]." win!";
  }
  elseif($record["AWAY-SCORE"] < $record["HOME-SCORE"])
  {
    print $record["HOME-NAME"]." win!";
  }
  else
  {
    print "Draw";
  }
  echo "<br/>";
}
function myRecord($round)
{
$roundNo = $round["R-ORD"];
}
  MagicParser_parse($filename,"myRecord","xml|ROUNDS/");
  MagicParser_parse($filename,"myRecordHandler","xml|ROUNDS/R/M/");
?>

Submitted by support on Sat, 2009-05-02 07:05

Hi Russell,

The way you are going about it is exactly right (2 record handlers), all you need to do is declare $roundno as global in each function so that they can both see the variable...

<?php
  
require("MagicParser.php");
  
$filename "http://xml.afl.com.au/expandablegamebar.aspx?roundid=710";
  function 
myRecordHandler($record)
  {
    global 
$roundNo;
    if (
$record["AWAY-SCORE"] > $record["HOME-SCORE"])
    {
      print 
$roundNo." - ";
      print 
$record["AWAY-NAME"]." win!";
    }
    elseif(
$record["AWAY-SCORE"] < $record["HOME-SCORE"])
    {
      print 
$record["HOME-NAME"]." win!";
    }
    else
    {
      print 
"Draw";
    }
    echo 
"<br/>";
  }
  function 
myRecord($round)
  {
    global 
$roundNo;
    
$roundNo $round["R-ORD"];
  }
  
MagicParser_parse($filename,"myRecord","xml|ROUNDS/");
  
MagicParser_parse($filename,"myRecordHandler","xml|ROUNDS/R/M/");
?>

Cheeers!
David.

Submitted by russellharrower on Sat, 2009-05-02 11:53

Ok what I am about to say might sound like what the, but i have no idea where to start with the next thing i have to do.

I need to match the home & away team names to the database, so i can get that teams ID which is in the database called afl_teams

then i need it to return the team ID form the ID row, the team names are in the name row.

Thanks

Submitted by support on Sat, 2009-05-02 11:58

Hi Russell,

Do you actually need to go to a database as I notice that there is an ID field in the record (based on your first post in this thread)...

$record["AWAY-ID"];

Cheers,
David.