class Profile extends CI_Controller {
public function gettype(){
$rs=$this->db->query('select * from tb_type');
echo json_encode($rs->result_array());
}
public function msgbox_show(){
$sql= "SELECT*FROM chat_msgbox where msg_start ='".$this->session->userdata('UserName')."' and msg_dest = '".$this->input->Post('Dest')."'" or msg_start ='".$this->input->Post('Dest')."' and msg_dest = '".$this->session->userdata('UserName')."' order by msg_no asc";
$rs=$this->db->query($sql);
echo json_encode($query->result_array());
}
Code (JavaScript)
$.post("" + baseUrl +"/chatcontroller/msgbox_show",
{
Dest: id ,
},
function(data){
var rs = $.parseJSON(data);
alert( rs.length());
for( var i=0; i<rs.length; i++){
alert(rs[i].msg_user)
}
});
}