2013-06-03 392 views
-2

顯示錶中的數據有點麻煩。一直在看我的代碼過去幾個小時,似乎無法看到問題。我想要做的是當一個團隊被點擊時會進入玩家表並顯示在團隊頁面上擁有該團隊名稱的任何玩家。我不斷收到一個空白頁:顯示來自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="&nbsp;"> 
      </td> 
      <td> 
       <p> 
        <a href="?action=view_player&amp;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()); 
    } 
} 
+0

看看'get_players_by_team'函數返回使用var_dump或print_r 並請張貼:) – Sedz

+0

什麼在您的Web服務器錯誤日誌?空白屏幕通常意味着PHP語法存在問題。 – andrewsi

+0

請考慮添加評論爲什麼投票這個 – Sedz

回答

0

你從來沒有定義$players它看起來像你期待什麼是$players實際上是$teams

$teams = get_players_by_team($team); 

而且你使用的$player在腳本的頂部,而不是循環這是沒有意義的內部。

+0

對不起,我是新來的PHP,只是試圖找出這個......所以我會使用球員作爲變量名稱:$ players = get_players_by_team($球隊); – user2446521

+0

在頁面頂部使用'error_reporting(E_ALL);'查看所有錯誤。 –

+0

我得到的錯誤是「爲foreach()提供的無效參數」 – user2446521

相關問題