Question: PHP SQL Query while loop query only shows only first value for all columns
<?php require 'db.inc.php'; $Name = $_POST['Name']; $NewHighScore = $_POST['HighScore']; $sql = "SELECT * FROM CovidShooter;"; $stmt = mysqli_stmt_init($conn); if (!mysqli_stmt_prepare($stmt, $sql)) { header("Location: index.php?error0=sqlerror"); exit(); } else { mysqli_stmt_execute($stmt); $result = mysqli_stmt_get_result($stmt); $n = 0; while ($row = mysqli_fetch_assoc($result)) { $HighScore.$n = $row['highscore']; $Rank.$n = $row['Rank']; echo $Rank.$n; echo $HighScore.$n; $n++; } } mysqli_stmt_close($stmt); mysqli_close($conn);
If I put the echo statment between $Highscore and $Rank both values show. However when I put the $Highscore right in front of the $Rank it will show the highscore value for both $Rank & $Highscore. When I switch the the order it will only show php error Rank value for $Rank & $Highscore. Why is that? Am I doing something wrong or maybe I am ignorant of a rule set with SQL. I dont know. Please provide insight if you have any. Thank you,
9codings