Reputation: 122
Trying to understand why when this page loads, there are no values for the $member['memberName'] and $member['memberDOB'] objects. Appreciate any help in advance, still learning php and MySQL. :)
Here's the HTML:
<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>
And the PHP:
} 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');
}
And here's the function:
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();
$statement->closeCursor();
$members = $statement->fetch();
return $members;
}
Upvotes: 0
Views: 51
Reputation: 122
After playing with it a few more hours, I changed the fetch() to fetchAll() - which solved the problem (along with removing the 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;
}
Upvotes: 1