Mysqli_fetch_row does not return results, but mysqli_fetch_assoc does

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
    // Perform database query
    $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
            // Use return data with mysqli_fetch_assoc
            while($row = mysqli_fetch_assoc($result)) {
                // output data from each row
        ?>
            <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 
            // Use return data with mysqli_fetch_row
            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
        // Release returned data
        mysqli_free_result($result);
    ?>

php , , . , , $result, , - ? , $row -, .

+4
1

. , , . - 0 $obj- > data_seek (int, .. 0); mysqli_data_seek ($ result, 0);

+3

All Articles