显示来自mysql的数据

时间:2013-06-03 20:00:06

标签: php 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());
    }
}

1 个答案:

答案 0 :(得分:0)

您永远不会定义$players它看起来像您期望的$players实际上是$teams

$teams = get_players_by_team($team);

此外,您在脚本顶部使用$player而不是在循环内部,这是没有意义的。