Reputation: 755
I have some variable and try to echoing them but I see empty result (test on live server). I cannot find my mistake, please help..
My controller:
function request($req)
{
$tiki_url = "http://203.77.231.130/services/api.cfc?method=tariff&origin=CGK01.00&destination={TO_AREA}&weight=1";
var_dump($tiki_url);
$code = array();
$this->db->select('*');
$this->db->where('request_id = ', $req );
$query = $this->db->get('excel');
$sql= $query->result_array();
var_dump($sql);
foreach ($sql as $key)
{
$ex =$key['excel_id'];
$zipcode = $key['to_zipcode'];
$request = $key['request_id'];
$this->db->select('tariff_code');
$this->db->where('zip_code = ', $zipcode );
$query = $this->db->get('area_info');
$tarif= $query->row_array();
$kodepos = $tarif['tariff_code'] ;
var_dump($kodepos);
if(isset($code[$kodepos]))
{
$tiki_data = $code[$kodepos];
}
else
{
$url = str_replace("{TO_AREA}",$kodepos,$tiki_url);
$tiki_data = json_decode(file_get_contents($url),TRUE);
$code[$kodepos] = $tiki_data ;
}
$tariff = $tiki_data['tariff'][3]['TARIFF'] ;
var_dump($tariff);
$data = array(
'tariff'=>$tariff,
);
var_dump($data);
$data_status = array(
'status' => '2',
);
var_dump($data_status);
$this->db->update('excel', $data, "excel_id =".$ex);
$this->db->update('request',$data_status, "request_id=".$request);
var_dump($key);
echo json_encode(array("status" => TRUE, "total" => $tariff,"excel" => $ex ));
}
}
All var_dump() returns nothing except the var_dump($tiki_url)
. I am sure there are several records in excel
table. I expected this result from echoing the json_encode (I capture this from testing on localhost):
Upvotes: 2
Views: 792
Reputation: 630
Only the first one returns the data, so we can guess that there was an error with SQL queries. You can check using the is_array() function.
...
$sql = $query->result_array();
if ( ! is_array($sql)) {
exit('Error.');
}
var_dump($sql);
...
Upvotes: 2