0
私はすべてのメッセージを取得し、配列にそれをすべて入れたいが、私は、たとえば、ソートすべてのIDによるメッセージを望む別の方法があります: 私のJSON:配列からのすべてのメッセージを取得する - PHP
{"msg_c":[{"message":"Hi","sender":"2","receve":"3","name":"Muhamad Bagzada"},{"message":"Hello","sender":"3","receve":"2","name":"Danyal Join"},{"message":"What's up , How are you ?","sender":"2","receve":"3","name":"Muhamad Bagzada"},{"message":"fine and you ?","sender":"3","receve":"2","name":"Danyal Join"},{"message":"fine","sender":"2","receve":"3","name":"Muhamad Bagzada"}]}
は、まさに私が欲しい:別の値によって、アレイ内の
ショーmessgaes、(message_u:私のMSG、messages_m:彼のMSG)
{
"msg_c":
[
{"message_u":"Hi","sender":"2","receve":"3","name":"Muhamad Bagzada"},
{"message_m":"Hello","sender":"3","receve":"2","name":"Danyal Join"},
{"message_u":"What's up , How are you ?","sender":"2","receve":"3","name":"Muhamad Bagzada"},
{"message_m":"fine and you ?","sender":"3","receve":"2","name":"Danyal Join"},
{"message_m":"fine","sender":"2","receve":"3","name":"Muhamad Bagzada"}
]
}
をPHPの機能:
public function MessageApp ($user_id,$sender){
$data ='';
$Messg = mysqli_query($this->_join, "SELECT * FROM `messages` WHERE (`from` = '$sender' AND `to` = '$user_id') OR (`from` = '$user_id' AND `to` = '$sender') ORDER BY dates ASC LIMIT 12 ");
while ($m = mysqli_fetch_assoc($Messg)) {
$from = $m['from'];
$to = $m['to'];
$chat = $m['chat'];
$dates = $m['dates'];
$id = $m['id'];
if ($user_id === $sender) {
$select_id = $to;
}else{
$select_id = $from;
}
$user = new user($from);
$fullname = ($user->data()->fname)." ".($user->data()->lname);
$gettype['msg_c'][] = array(
'message' => $chat,
'sender' => $from,
'receve' => $to,
'name'=>$fullname
);
$data = json_encode($gettype);
}
return json_encode($gettype);
}
私はここにJSONデータと呼ばれる:
<?php
include $_SERVER['DOCUMENT_ROOT']."/php/core/init.php";
include $_SERVER['DOCUMENT_ROOT']."/php/core/connect.php";
$my_id = input::get('user_id');
$user = new user($my_id);
$sender = $user->data()->id;
$db = db::getInstance();
$message = new message();
$id = input::get("id");
$user = new user($id);
$user_id = $user->data()->id;
echo $message->MessageApp($user_id,$sender);
?>
そこに多くの方法があるが、それは、AndroidのためですプロジェクトとJSONオブジェクトを、私が使用している場合(else文の場合)の解析、JSONは、配列PHPから一つの値を受け入れます –