I have a function to convert record from SQL query result into JSON array. This is my function:
function createJson(){
$dir="img/e-commerce/product/"
$sql=mysql_query("SELECT product_list.id AS listId, product_list.class AS listClass,
product.prod_name AS prodName, product.prod_url AS prodUrl,
product.prod_overview AS prodOverview,
product_img.list_prod340x340 AS prodListImg,
MIN(pricelist.price) AS price
FROM (((product_list
INNER JOIN product_img ON product_list.id = product_img.prod_list_id)
INNER JOIN product ON product_list.id = product.prod_list_id)
INNER JOIN pricelist ON product.id = pricelist.prod_id)
GROUP BY listId, listClass, prodName, prodUrl,
prodOverview, prodListImg
ORDER BY product_list.id, price ASC");
while($prodList= mysql_fetch_array($sql)){
$data['items'][] = array(
'name' => $prodList['prodName'],
'description' => $prodList['prodOverview'],
'price' => $prodList['price'],
'image' => $prodList['prodListImg'],
'category' => $prodList['listClass'],
'prod_url' => $prodList['prodUrl'],
));
}
$path = 'api/';
$jsonfile = json_encode($data, JSON_PRETTY_PRINT);
$fcon = file_put_contents($path.'anggota.json', $jsonfile);}
And this is how the result looks like:
{
"items": [
{
"name": "Toyota Agya",
"description": "Ringkasan produk",
"price": "155500000",
"image": "..\/img\/e-commerce\/producttoyota_agya_340x340.jpg",
"category": "Hatchback",
"prod_url": "harga-mobil-toyota-agya-terbaru"
},
{
"name": "Toyota Calya",
"description": "overview produk",
"price": "151600000",
"image": "..\/img\/e-commerce\/product\/toyota-calya_340x340.jpg",
"category": "MPV",
"prod_url": "toyota-calya"
}
]}
It keep adding \ before /. Can you help me solve this?