顯示錶中的數據有點麻煩。一直在看我的代碼過去幾個小時,似乎無法看到問題。我想要做的是當一個團隊被點擊時會進入玩家表並顯示在團隊頁面上擁有該團隊名稱的任何玩家。我不斷收到一個空白頁:顯示來自mysql的數據
的index.php
這是啓動team_view.php
case 'view_team':
$team = $_GET['name'];
$teams = get_players_by_team($team);
include('team_view.php');
break;
team_view.php
<?php include '../../view/header.php'; ?>
<?php include '../../view/sidebar_admin.php'; ?>
<div id="content">
<h1>Team Roster</h1>
<!-- display product -->
<?php include '../../view/team.php'; ?>
<!-- display buttons -->
</div>
<?php include '../../view/footer.php'; ?>
的情況下team.php
<?php
$team = $team['name'];
$first = $player['first'];
$last = $player['last'];
$age = $player['age'];
$position = $player['position'];
$team = $player['team'];
?>
<table>
<?php foreach ($players as $player) :
?>
<tr>
<td id="product_image_column" >
<img src="images/<?php echo $player['player_id']; ?>_s.png"
alt=" ">
</td>
<td>
<p>
<a href="?action=view_player&player_id=<?php echo
$player['player_id']; ?>">
<?php echo $player['first']; ?>
<?php echo $player['last']; ?>
</a>
</p>
</td>
</tr>
<?php endforeach; ?>
</table>
product_db.php
<?php
function get_players_by_team($team) {
global $db;
$query = 'SELECT * FROM players
WHERE team = :team';
try {
$statement = $db->prepare($query);
$statement->bindValue(':team', $team);
$statement->execute();
$result = $statement->fetch();
$statement->closeCursor();
return $result;
} catch (PDOException $e) {
display_db_error($e->getMessage());
}
}
看看'get_players_by_team'函數返回使用var_dump或print_r 並請張貼:) – Sedz
什麼在您的Web服務器錯誤日誌?空白屏幕通常意味着PHP語法存在問題。 – andrewsi
請考慮添加評論爲什麼投票這個 – Sedz