I started learning PHP and Databases today.
What I tried so far and worked is to access information from a database using a simple updateScores.php file.
DB high_scores:
names | scores |
___________________
player1 | 20 |
player2 | 69 |
My code:
$host="localhost";
$database="players";
$user="root";
$password = "";
$error = "Cant connect";
$con = mysqli_connect($host, $user, $password);
mysqli_select_db($con, $database) or die("Unable to connect!");
$query = "SELECT * FROM high_scores";
$result = mysqli_query($con, $query);
$n = mysqli_num_rows($result);
for($i=0; $i<$n; $i++){
$name = mysqli_fetch_assoc($result)["name"];
$score = mysqli_fetch_assoc($result)["score"];
echo "Name : ".$name;
echo "Score : ".$score;
}
?>
This works fine when i execute http://localhost/updateScores.php
However when i change the last two lines to
echo $name."\t";
echo $score."\n";
I only get the first name (player1) and the last score (69) Why this is happening? Any help and additional link would be great. Thanks.

header('Content-Type: text/plain');for it to work in browser