I'm trying to generate json from a mysql statement using the following code:
while($row = mysqli_fetch_array($r))
{
$arr_brand[] = array('ID' => $row['ID'],'Name' => $row['brand_name']);
$arr_brands[] = array('Brand' => $arr_brand);
}
however, This is how the JSON is coming out:
[{
Brand: [{
ID: "1",
Name: "CocaCola"
}]
}, {
Brand: [{
ID: "1",
Name: "CocaCola"
}, {
ID: "2",
Name: "Fanta"
}]
}]
As you can see it is duplicating the first row in the database. Why is this and how can I stop it?
Thanks
$arr_brand[] = "something"appends"somrthingto the array. You probably wanted reassignment$arr_brand = "something".