I think this a symptom of a flawed design. Looks like you're trying to find the scores for 3 players. You're looping over the 3 rows but trying to access the data for all 3 players in each iteration. You should instead access each player's data in their respective iteration and build up a list of player data.
To answer your question directly, on iteration 1 you are trying to access element 0, 1, and 2 but $rows
is only populated with 0.
+-----------+-------------------------+--------------------------+
| Iteration | You're trying to access | You only have access to |
+-----------+-------------------------+--------------------------+
| 1 | 0,1,2 | 0 |
| 2 | 0,1,2 | 0,1 |
| 3 | 0,1,2 | 0,1,2 |
+-----------+-------------------------+--------------------------+
Example
<?php
// Turn on error reporting
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// Show MySQL errors as PHP exceptions
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
include '../connect_database.php';
// Build up this list inside the loop.
$scores = [];
$sql = "SELECT score FROM dailyscore Where Id IN (1,2,3)";
date_default_timezone_set('America/New_York');
$result = $connect->query($sql);
while ($row = mysqli_fetch_assoc($result)){
// You only have access to a single $row here.
// Build up an array of the data you want instead of tring to access "other rows"
$scores[] = $row['score'];
}
// Now, you can use $scores to build $list... or build $list inside the loop.
?>
EDIT
Do you mind to show me example how to assign the array results to
something like this? $list['scores'] = array('data' => $id1, 'data1'
=> $id2, 'data2' => $id3);
<?php
// Turn on error reporting
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// Show MySQL errors as PHP exceptions
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
include '../connect_database.php';
// Build up this list inside the loop.
$scores = [];
$counter = 0;
$sql = "SELECT score FROM dailyscore Where Id IN (1,2,3)";
date_default_timezone_set('America/New_York');
$result = $connect->query($sql);
while ($row = mysqli_fetch_assoc($result)){
$keyName = 'data';
if ($counter > 0) {
$keyName = 'data' . $counter;
}
$scores[$keyName] = $row['score'];
$counter++;
}
$list['scores'] = $scores;
echo json_encode($list);