您可以将播放器的gamertag
添加到查询参数中,例如:
echo "<a href='detailpage.php?player={$allPlayersItem['gamertag']}'>".$allPlayersItem['gamertag']."</a>";
然后在detailpage.php
中,您可以编写:
$player = $_GET['player'] ?? '';
if ($player != '') {
// display player details...
}
请注意,如果gamertag
值可能包含特殊字符,那么在将其用作参数之前,应先urlencode
值,即
echo "<a href='detailpage.php?player=" . urlencode($allPlayersItem['gamertag']) . "'>".$allPlayersItem['gamertag']."</a>";
,
首先,我建议您划分从数据库获取数据和呈现数据的责任。最常见的方法可能是遵循MVC模式。
类似的东西:
# Controller/PlayerController
final class PlayerController
{
public function index(): Response
{
$players = [/* list of players to display. From the DB,for example*/];
return $this->render('player/index.[blade|twig|php]',$players);
}
}
# Views/player/index.php
<?php foreach ($players as $player): ?>
<a href='detailpage.php'>" . <?= $player['gamertag']?> . "</a><br>"
<?php endforeach ?>
我建议您使用google研究并了解有关此主题的更多信息。
本文链接:https://www.f2er.com/3138785.html