I will get team_name from previous page and then I want to show all the players with that team name in the browser.
But it gives error and when I try to print variable $players
it has only details of one player with that team name.
I think the result of query must be stored in some kind of 2-D array but I am not able to think the logic behind it.
Player Table has attributes
- player_name
- jearsy_no
- team_name
- phone_no
- dob
<?php
include('config/db_connect.php');
if(isset($_GET['team_name'])) {
$team_name = mysqli_real_escape_string($conn, $_GET['team_name']);
$sql_players = "SELECT * FROM player WHERE team_name = '$team_name'";
$result_players = mysqli_query($conn, $sql_players);
$players = mysqli_fetch_assoc($result_players);
//print_r($players);
}
?>
<!DOCTYPE html>
<html>
<?php include('templates/header.php'); ?>
<?php foreach($players as $player) : ?>
<div class="container">
<h6><?php echo htmlspecialchars($player['player_name']); ?></h6>
</div>
<?php endforeach; ?>
<?php include('templates/footer.php'); ?>
</html>
I get this error:
Warning: Illegal string offset 'player_name'
And when I try to print_r($players)
I get:
Array ( [player_name] => Dwayn Miller
[jearsy_no] => 32
[team_name] => Team Australia
[dob] => 1998-12-11
[player_phone] => 4009871234
)