I am trying to import three arrays from php into js using json_encode
Here is the code:
<?php
    $query2 = "SELECT * FROM all_data";
    $result2 = $conn->query($query2);
    $bu = [];
    $rank = [];
    $id = [];
    if ($result2->num_rows > 0) {
        while($row2 = $result2->fetch_assoc()) {
            $bu[] = $row2["bu"];
            $rank[] = $row2["rank"];
            $id[] = $row2["id"];
            echo "<tr class='dn' id='u-" . $row2["rank"] . "'>";
            echo "<td>" . $row2["rank"] . "</td>";
            echo "<td>" . $row2["bu"] . "</td>";
            echo "<td>" . $row2["tokens"] . "</td>";
            echo "</tr>";
        }
    }
    ?>
    var users = <?php echo json_encode($bu); ?>;
    var ranks = <?php echo json_encode($rank); ?>;
    var identifier = <?php echo json_encode($id); ?>;
Problem is, the arrays ranks and identifier are getting imported correctly, but users is not. This script was working the last few times I used it. Recently however, I changed the table all_data, by dropping it and then importing it from csv again. However the charset was utf8 when I imported, so I don't understand what the problem might be here.
Even if I am just doing <?php echo json_encode($bu) ?> it is not working. However <?php print_r($bu) ?> shows me that the array is not actually empty and it actually contains the query results.
 
     
    