Попробуйте это, это работает для вас .....
<?php
$server_name="localhost";
$mysql_user="root";
$db_name ="db_mtma";
$mysql_pass ="";
mysql_connect($server_name, $mysql_user,"");
mysql_select_db($db_name);
// $con = mysqli_connect($server_name,$mysql_user,$mysql_pass,$db_name);
$result = array();
$query = "SELECT id_lw,gambar_lw,nama_p,COUNT(nama_p) AS jumlah_lw_by_nama_p,nama_k,COUNT(nama_k)
from lokasi_wisata JOIN
provinsi as provinsi ON provinsi.IDProvinsi = lokasi_wisata.IDProvinsi JOIN
kabupaten as kabupaten ON kabupaten.IDKabupaten = lokasi_wisata.IDKabupaten WHERE status_lw=1 GROUP BY nama_p" ;
$res = mysql_query($query);
$result=array();
while ($fetch = mysql_fetch_assoc($res)) {
$result['id_lw'][$fetch['id_lw']] = $fetch;
}
// print_r($result);
echo mysql_error();
echo json_encode(array('result'=>$result));