i have question how result query in codeigniter, need value of result query send ajax json_encode.
the script this..
public function getpost() { $getcode = $_post['part_code']; $query = $this->db->query('select count(*) + 1 count tb_transaction part_code ='%$getcode%''); foreach ($query->result('tb_transaction') $row) { echo $row->count; // call attributes } $phpvar = array("status"=>$row->count); echo json_encode ($status) ; }
my ajax function this..
<script> function makeajaxcall() { $.ajax({ type: "post", url: "http://localhost/iwos_ci/trans_invent_controller/getpost", cache: false, data: $('#form1').serialize(), success: function(json){ try{ var obj = jquery.parsejson(json); var r = obj['status']; }catch(e) { alert('exception while request..'); } }, error: function(){ alert('error while request..'); } }); }
i create function in controller not model. , attention.
try this, need modify suit code though:
<script type="text/javascript"> function makeajaxcall() { $.ajax({ type: "post", url: "http://localhost/iwos_ci/trans_invent_controller/getpost", cache: false, data: $('#form1').serialize(), success: function(json){ if(json){ var statusr = json.status; alert( "status : "+statusr ); }else{ alert( "error in json" ); } }, error: function(){ alert('error while request..'); } }); } </script> <?php function getpost() { $getcode = $_post['part_code']; $query = $this->db->query( "select count(*) + 1 count videos id = '%$getcode%'" ); //echo $this->db->last_query(); die; $querydata = $query->row_array(); $phpvar = array( "status" => $querydata['count'] ); echo json_encode ( $phpvar ) ; } ?>