I am writing a simple php page for assignment, and one of the criteria is to use both mysqli_fetch_assoc and mysqli_fetch_row. I use the same query for both:
<?php
$query = "SELECT * FROM player JOIN stat ON player.playerId = stat.playerId";
$result = mysqli_query($dbconnection, $query);
if (!$result) {
die("Database query failed");
}
?>
When I run this query in my database, it returns 3 rows as expected. On my webpage, I first use mysqli_fetch_assoc ($ result) and it displays an unordered list with information as expected. Then I will move on to using mysqli_fetch_row ($ result) to display more information, but the second while loop does not give any table data (only the contents of the t-techs).
<h1>The Players</h1>
<ul>
<?php
while($row = mysqli_fetch_assoc($result)) {
?>
<li><?php echo $row["playerId"]; ?></li>
<li><?php echo $row["fname"] . " " . $row["lname"]; ?></li>
<li><?php echo $row["team"]; ?></li>
<li><?php echo $row["position"]; ?></li>
<?php echo "<hr />";
}
?>
</ul>
<h1>The Stats</h1>
<table>
<th>Player</th>
<th>Batting Avg</th>
<th>Homeruns</th>
<th>RBIs</th>
// DATA BELOW THIS POINT IS NOT RENDERED BY THE WEBPAGE
<?php
while($row = mysqli_fetch_row($result)) {
?>
<tr>
<td><?php echo $row[2]; ?></td>
<td><?php echo $row[8]; ?></td>
<td><?php echo $row[9]; ?></td>
<td><?php echo $row[10]; ?></td>
</tr>
<?php
}
?>
</table>
<?php
mysqli_free_result($result);
?>
php , , . , , $result, , - ? , $row -, .