Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $this->db->where('group_chat','xyxy');
- $this->db->order_by('waktu', 'ASC');
- $get=$this->db->get('chat');
- if($get->num_rows()>0){
- $data1=array();
- $data2=array();
- $no=1;
- foreach ($get->result() as $key) {
- $penentu='';
- if($no%2==1){
- $penentu='left';
- }else{
- $penentu='right';
- }
- $data1['no'.$no]=$key->chat;
- $data2['no'.$no]=$penentu;
- $no++;
- }
- $data=array(
- 'text' => $data1,
- 'position' => $data2
- );
- echo json_encode($data);
- }else{
- }
- //output
- {"text":{"no1":"Tes aja","no2":"Tes juga","no3":"Hallo","no4":"Hai"},
- "position":{"no1":"left","no2":"right","no3":"left","no4":"right"}}
- maunya:
- [
- {
- 'text' : 'Tes aja',
- 'position' : 'left'
- },
- {
- 'text' : 'Tes juga',
- 'position' : 'right'
- },
- {
- 'text' : 'THallo',
- 'position' : 'left'
- },
- {
- 'text' : 'Hai',
- 'position' : 'right'
- }
- ]
Add Comment
Please, Sign In to add comment