我想从android到我的服务器获取使用CodeIgniter框架的数据。但是当我想通过在mysql数据库上执行内连接来获取“标记”数据时,我遇到了问题。但在Android上,它总是得到result==false
。
这是我的android源代码
protected void onPostExecute(final Boolean result) {
dialog.cancel();
runOnUiThread(new Runnable() {
@Override
public void run() {
if (result == false) {
showInfo();
} else {
for (int i = 0; i < array.size(); i++) {
HashMap<String, String> newMap = new HashMap<String, String>();
newMap = array.get(i);
mMyMarkersArray.add(new MyMarker(newMap.get("nama"), newMap.get("deskripsi"), newMap.get("foto"), newMap.get("marker"), Double.parseDouble(newMap.get("lat")), Double.parseDouble(newMap.get("lng"))));
}
plotMarkers(mMyMarkersArray);
}
}
});
}
Codeigniter(控制器)源代码
public function getContentLocation(){
$response=array();
$result = $this->m_krb->getAllContent();
if ($result->num_rows() > 0) {
$response["konten"] = array();
foreach($result->result() as $row):
$pendaftaran = array();
$pendaftaran["id"] = $row->id_table_petakrb;
$pendaftaran["nama"] = $row->nama_petakrb;
$pendaftaran["deskripsi"] = $row->deskripsi;
$pendaftaran["foto"]='http://192.168.43.137/navigasikrb/assets/img/foto/'.$row->foto;
$icon = $row->marker_icon;
$marker = $this->m_krb->checkGroup($icon)->result();
$pendaftaran["marker"] = $marker->nama_group;
$pendaftaran["lng"] = $row->longitude;
$pendaftaran["lat"] = $row->latitude;
array_push($response["konten"], $pendaftaran);
endforeach;
// sukses
$response["success"] = 1;
// echo JSON response
echo json_encode($response);
} else {
$response["success"] = 0;
$response["message"] = "Tidak ada data yang ditemukan";
echo json_encode($response);
}
}
Codeigniter(模型)源代码
function getAllContent(){
$query=$this->db->query("select * from table_petakrb ");
return $query;
}
function checkGroup($icon){
$query=$this->db->query("select table_group.nama_group FROM table_group INNER JOIN table_petakrb ON table_petakrb.marker_icon = table_group.file_icon WHERE table_petakrb.marker_icon = '$icon' ");
return $query;
}
但是,如果我改变这样的codeigniter控制器源代码,它可以在android上成功获取数据。
public function getContentLocation(){
$response=array();
$result = $this->m_krb->getAllContent();
if ($result->num_rows() > 0) {
$response["konten"] = array();
foreach($result->result() as $row):
$pendaftaran = array();
$pendaftaran["id"] = $row->id_table_petakrb;
$pendaftaran["nama"] = $row->nama_petakrb;
$pendaftaran["deskripsi"] = $row->deskripsi;
$pendaftaran["foto"]='http://192.168.43.137/navigasikrb/assets/img/foto/'.$row->foto;
$pendaftaran["marker"] = $row->marker_icon;
$pendaftaran["lng"] = $row->longitude;
$pendaftaran["lat"] = $row->latitude;
array_push($response["konten"], $pendaftaran);
endforeach;
// sukses
$response["success"] = 1;
// echo JSON response
echo json_encode($response);
} else {
$response["success"] = 0;
$response["message"] = "Tidak ada data yang ditemukan";
echo json_encode($response);
}
}
但问题是我在编写上面的源代码时无法使用内连接获取数据。我的代码有问题吗?