0

i can't find a way to make the JSON page separate the records into multiple lines and not stack into the same one.

my version

what im trying to achieve

<html>
    <head>
        <meta charset="UTF-8">
        <title>Task1</title>
    </head>
    <body>
        <?php
        $dsn = "mysql:host=localhost;dbname=egamesdb";
        $username = "root";
        $password = "";

        $pdo = new PDO($dsn, $username, $password);
        $sql = "select * from games";
        $statement = $pdo->query($sql);
        
        $statement->setFetchMode(PDO::FETCH_ASSOC);

        $records = $statement->fetchAll();
        
        

        foreach ($records as $row) {
            echo $row['name'] . ", " . $row['category'] . ", " .$row['creator'] . ", "
            .$row['monthly_subscription']. ", " .$row['platform'].", " .$row['filename'] . "<br>";
        }
         $json_data = json_encode($records);
        $f = fopen("dbconfig.json", "w");
        $rows = array($records);
        
        fwrite($f, $json_data);
        fclose($f);
        ?>
    </body>
</html>
Shadow
  • 33,525
  • 10
  • 51
  • 64

0 Answers0