Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $this->db->where('group_chat','xyxy');
  2. $this->db->order_by('waktu', 'ASC');
  3. $get=$this->db->get('chat');
  4. if($get->num_rows()>0){
  5.     $data1=array();
  6.     $data2=array();
  7.     $no=1;
  8.     foreach ($get->result() as $key) {
  9.         $penentu='';
  10.         if($no%2==1){
  11.             $penentu='left';
  12.         }else{
  13.             $penentu='right';
  14.         }
  15.  
  16.         $data1['no'.$no]=$key->chat;
  17.         $data2['no'.$no]=$penentu;
  18.         $no++;
  19.     }
  20.     $data=array(
  21.         'text'     => $data1,
  22.         'position' => $data2
  23.     );
  24.     echo json_encode($data);
  25. }else{
  26. }
  27.  
  28. //output
  29. {"text":{"no1":"Tes aja","no2":"Tes juga","no3":"Hallo","no4":"Hai"},
  30. "position":{"no1":"left","no2":"right","no3":"left","no4":"right"}}
  31.  
  32. maunya:
  33. [
  34.     {
  35.         'text'     : 'Tes aja',
  36.         'position' : 'left'
  37.     },
  38.     {
  39.         'text'     : 'Tes juga',
  40.         'position' : 'right'
  41.     },
  42.     {
  43.         'text'     : 'THallo',
  44.         'position' : 'left'
  45.     },
  46.     {
  47.         'text'     : 'Hai',
  48.         'position' : 'right'
  49.     }
  50. ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement