试图理解为什么在加载此页面时,$ member [' memberName']和$ member [' memberDOB']对象没有值。提前感谢任何帮助,仍在学习php和MySQL。 :)
这是HTML:
z-index
PHP:
<table>
<tr>
<th>Player Name</th>
<th>Player Date of Birth</th>
</tr>
<?php foreach ((array)$members as $member) : ?>
<tr>
<td><?php echo $member['memberName']; ?></td>
<td><?php echo $member['memberDOB']; ?></td>
</tr>
<?php endforeach; ?>
</table>
以下是功能:
} else if ($action == 'view_team_members') {
$team_id = filter_input(INPUT_GET,'team_id');
$team_name = get_team_name($team_id);
$members = get_team_members($team_id);
include('/view/team_members.php');
}
答案 0 :(得分:1)
在玩了几个小时后,我将fetch()更改为fetchAll() - 这解决了问题(同时删除了closeCursor())。
function get_team_members($team_id) {
global $db;
$query = 'SELECT * FROM members
WHERE teamID = :team_id';
$statement = $db->prepare($query);
$statement->bindValue(':team_id', $team_id);
$statement->execute();
$members = $statement->fetchAll();
return $members;
}