I have a JSON file with PHP, and I want to remove the last comma, because it causes an error. The code is the following:
{
"data": [
<?php
require_once("../../config.php");
$qtodos = $mysqli->query("SELECT * FROM negocios");
while($todos = $qtodos -> fetch_assoc()) {
?>
{
"id": <?php echo $todos['idnegocios']; ?>,
"category": "real_estate",
"title": "<?php echo $todos['nombre']; ?>",
"location": "<?php echo $todos['direccion']; ?>",
"latitude": 51.541599,
"longitude": -0.112588,
"url": "item-detail.html",
"type": "Apartment",
"type_icon": "assets/icons/store/apparel/umbrella-2.png",
"rating": 4,
"gallery":
[
"assets/img/items/1.jpg",
"assets/img/items/5.jpg",
"assets/img/items/4.jpg"
],
"features":
[
"Free Parking",
"Cards Accepted",
"Wi-Fi",
"Air Condition",
"Reservations",
"Teambuildings",
"Places to seat"
],
"date_created": "2014-11-03",
"price": "$2500",
"featured": 0,
"color": "",
"person_id": 1,
"year": 1980,
"special_offer": 0,
"item_specific":
{
"bedrooms": 4,
"bathrooms": 2,
"rooms": 4,
"garages": 1,
"area": 240
},
"description": "asasasas odio nibh, luctus non pulvinar a, ultricies ac diam. Donec neque massa, viverra interdum eros ut, imperdiet pellentesque mauris. Proin sit amet scelerisque risus. Donec semper semper erat ut mollis. Curabitur suscipit, justo eu dignissim lacinia, ante sapien pharetra duin consectetur eros augue sed ex. Donec a odio rutrum, hendrerit sapien vitae, euismod arcu.",
"last_review": "Curabitur odio nibh, luctus non pulvinar a, ultricies ac diam. Donec neque massa, viverra interdum eros ut, imperdiet",
"last_review_rating": 5
},
<?php
}
?>
]
}
I tried lots of solutions but never works in this code. I don't know when it is the last itineration of the loop, and can't remove it.