0

对于我正在处理的项目,我需要查询一个 XML URL 并使用预定的特许经营 ID 检索玩家列表。使用这些球员 ID,我需要查询第二个 XML URL 并检索球员姓名和球队,然后将其显示在列表中。

这是我正在尝试做的事情:

第一次查询

网址: http://football99.myfantasyleague.com/2007/export?TYPE=rosters& L=46184

  • 我需要选择在预定特许经营 ID 下列出的每个玩家 ID。

第二次查询

网址: http: //football.myfantasyleague.com/2013/export?TYPE=players &PLAYERS=3291

  • 在这里,我需要能够使用我们在第一个查询中从特定特许经营 id 检索到的球员 id 来检索球员姓名和球队。

毕竟,我希望第二个查询的结果显示在列表中。

这意味着从第一个查询中可以检索到 15 个玩家 id 之类的东西,并且使用这些玩家 id,我需要找出一种方法来获取每个玩家的姓名和球队。

有人愿意在这里帮助我吗?如果你问,我可以提供更多信息。

// Parse and display
$data=array();

$url1 = "http://football99.myfantasyleague.com/2007/export?TYPE=rosters&L=46184";
$xml = simplexml_load_file($url1);
 foreach($xml->franchise->player as $franchise_one) {
  $id=(string) $franchise_one->attributes()->id;
  $data[$id]['id']=(string) $franchise_one->attributes()->id;
  $data[$id]['playerid']=(string) $franchise_one->attributes()->id;
 }

/* Query list to get player names and teams using the player ids from above */
$url2 = "http://football.myfantasyleague.com/2013/export?TYPE=players&PLAYERS=3291";
$xml_second = simplexml_load_file($url2);
 foreach($xml_second->players->player as $player) {
  $id=(string) $player->attributes()->id;
   $data[$id]['name']=(string) $player->attributes()->name;
 }

while(list($key,$franchise)=each($data)) {
 $list .= 'Franchise id: '.$franchise['id'].'<br/>Player id: '.$franchise['playerid'].'<br/>Player name: '.$player['name'].'<br/><br/>';
}

结果

Warning: Invalid argument supplied for foreach() in --- on line 41

Franchise id: 8025
Player id: 8025
 Player name: l

Franchise id: 7394
Player id: 7394
 Player name: l

Franchise id: 6780
Player id: 6780
 Player name: l

Franchise id: 7740
Player id: 7740
 Player name: l

Franchise id: 5004
Player id: 5004
 Player name: l

Franchise id: 5656
Player id: 5656
 Player name: l

Franchise id: 4914
Player id: 4914
 Player name: l

Franchise id: 6562
Player id: 6562
 Player name: l

Franchise id: 7403
Player id: 7403
 Player name: l

Franchise id: 7393
Player id: 7393
 Player name: l

Franchise id: 8266
Player id: 8266
 Player name: l

Franchise id: 6528
Player id: 6528
 Player name: l

Franchise id: 7653
Player id: 7653
 Player name: l

Franchise id: 6952
Player id: 6952
 Player name: l

Franchise id: 8339
Player id: 8339
 Player name: l

Franchise id: 8074
Player id: 8074
 Player name: l

Franchise id: 0521
Player id: 0521
 Player name: l
4

1 回答 1

0

这成功了。

$year         = '2007';
$league       = '46184';
$franchise_id = '0001';

// Parse and display
$data=array();

// Get players for each franchise
$url = 'http://football99.myfantasyleague.com/'.$year.'/export?TYPE=rosters&L='.$league.'&FRANCHISE='.$franchise_id.'';
$xml = simplexml_load_file($url);
 foreach($xml->franchise->player as $franchise_two) {
  $player_id=(string) $franchise_two->attributes()->id;
   $data[$player_id]['playerid']=(string) $franchise_two->attributes()->id;

    // Create a list of player ids
    $player_list = ''.$data[$player_id]['playerid'].',';

     // Parse players
     $players = simplexml_load_file('http://football.myfantasyleague.com/2013/export?TYPE=players&PLAYERS='.$player_list.'');
      foreach ($players as $player):
       $player_name=$player['name'];
      endforeach;

       // Display output
       while(list($key,$franchise)=each($data)) {
        $list .= 'Franchise id: '.$franchise_id.'<br/>Player id: '.$franchise['playerid'].'<br/>Player name: '.$player_name.'<br/><br/>';
       }
}

echo ''.$list.'';

回声结果

特许经营编号:0001

玩家编号:8025

球员姓名:安德森、德里克

ETC...

于 2013-05-28T14:03:49.890 回答