samedi 11 mars 2017

Not updating data on json file but my code is correct via PHP

I'm a newbie here so please be with. I'm pretty sure that my code and syntax is correct.

This is my json file

{"data":
    [
        {"label":"Signed-in Client","value":2
        }
    ]
}

This is my php code

<?php


    $conn=mysqli_connect("localhost", "root","","something");
    $res1 = mysqli_query($conn, "SELECT * FROM tbl_pet_owner ORDER BY pet_owner_id");
    $max1 = mysqli_num_rows($res1);

    $jsonString = file_get_contents('data.json');
    $data1 = json_decode($jsonString, true);
    foreach ($data1['data'] as $key ) 
    {
    if ($key[0]['label'] == "Signed-in Client") 
        {
            $data1['value'] = $max1;
        }
    }
    $newJsonString = json_encode($data1);
    file_put_contents('data.json', $newJsonString);
?>

but when I refresh, it doesn't update with the max count of my query. I hope you'd help me. This is for my thesis




Aucun commentaire:

Enregistrer un commentaire