我现在可以为URL中的每一行数据显示正确的ID。但是现在我希望在另一个屏幕上显示它。 我正在努力弄清楚如何从最初获取的ID中提取诸如“玩家”或“团队”之类的数据。 我希望将这些数据显示在GameInfo页面的表格中。
感谢您的帮助。谢谢
例如:
=========================
public function getMatchInfo() {
$url = $this->buildUrl('scores/events.json?
key=Ka88B6jZrxO8dDQt&secret=L233yXpNCWQDZyxJIGSkNbjeI8nWLdqw&id=1"');
return $this->makeRequest($url);
}
在这里我必须指定令人讨厌的ID,因为这些ID在游戏之间会发生变化。 有什么方法可以编辑以从索引页面提取ID?从索引页面显示当前的“实时游戏”,然后单击链接以打开“游戏信息”页面,在该页面中我要从API中提取数据。
=====================
<?php
include 'config.php';
include 'functions.php';
include 'myapp.php';
$Api = new LivescoreApi();
$data = $Api->getLiveScores();
$timezone = 'Europe/Istanbul';
?>
<html>
<head>
<link rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh"
crossorigin="anonymous">
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-3">
</div>
<div class="col-md-6">
<table class="table table-bordered">
<tr class="table-info">
<th>KO</th>
<th>Time</th>
<th>Home</th>
<th>Score</th>
<th>Away</th>
</tr>
<?php foreach ($data['data']['match'] as $_match) { ?>
<tr>
<td><?= convert($_match['scheduled'], $timezone) ?></td>
<td><?= $_match['time'] ?></td>
<td style="text-align: right;"><?= $_match['home_name'] ?></td>
<td style="text-align: center;"><?= $_match['score'] ?></td>
<td><?= $_match['away_name'] ?></td>
<td style="text-align: right;"><a href="gameInfo.php"> Game
information </a><?= $_match['id'] ?></td>
</tr>
<?php } ?>
</table>
</div>
<div class="col-md-3">
</div>
</div>
</div>
</body>
</html>
=================
<tr class="table-info">
<h2 style="text-align: center;"> Game Info </h2>
<th>Player Name</th>
<th>Event</th>
<th>Time</th>
</tr>
<?php foreach ($data['data']['event'] as
$_event){ ?>
<tr>
<td style="text-align: center;"><?=
$_event['player'] ?></td>
<td style="text-align: center;"><?=
$_event['event'] ?></td>
<td style="text-align: center;"><?=
$_event['time'] ?></td>
答案 0 :(得分:3)
很可能我不理解您的问题。创建表单,以便在$_GET["id"]
变量中发送ID?
答案 1 :(得分:3)
我认为您只想将已经拥有的ID传递给函数?
public function getMatchInfo() {
if(isset($_GET['id']){
$id = $_GET['id']
} //this check entirely optional, but I'd do it
else{
$id = 1; //or some other default you want, or error handling here
}
$url = $this->buildUrl('scores/events.json?
key=Ka88B6jZrxO8dDQt&secret=L233yXpNCWQDZyxJIGSkNbjeI8nWLdqw&id='.$id);
return $this->makeRequest($url);
}
<?php
include 'config.php';
include 'functions.php';
include 'myapp.php';
$Api = new LivescoreApi();
$data = $Api->getLiveScores();
$timezone = 'Europe/Istanbul';
?>
<html>
<head>
<link rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh"
crossorigin="anonymous">
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-3">
</div>
<div class="col-md-6">
<table class="table table-bordered">
<tr class="table-info">
<th>KO</th>
<th>Time</th>
<th>Home</th>
<th>Score</th>
<th>Away</th>
</tr>
<?php foreach ($data['data']['match'] as $_match) { ?>
<tr>
<td><?= convert($_match['scheduled'], $timezone) ?></td>
<td><?= $_match['time'] ?></td>
<td style="text-align: right;"><?= $_match['home_name'] ?></td>
<td style="text-align: center;"><?= $_match['score'] ?></td>
<td><?= $_match['away_name'] ?></td>
<td style="text-align: right;"><a href="gameInfo.php?id=<?= $_match['id'] ?>"> Game
information </a><?= $_match['id'] ?></td>
</tr>
<?php } ?>
</table>
</div>
<div class="col-md-3">
</div>
</div>
</div>
</body>
</html>
答案 2 :(得分:0)
所以我想出了我最新问题的答案。 我最初没有添加“ isSet()”检查。 我现在这样做了,而且我也缺少牙套。 我猜不使用IDE编写代码的乐趣。