JSON数组user1和用户2插入

时间:2014-09-06 17:06:42

标签: php arrays ajax json

下午。我正在尝试将user1和user2数组的用户名添加到消息div中,并在我的控制台响应中获得以下内容

{"user1":{"0":[],"num":30,"message_id":"392","message_content":"ggg","message_creator":"3","message_target":"34","message_throughurl":"..\/pm.php?id=3&id2=34","message_time":"2014-09-06 17:55:45","username":"Me","id":"3","first":"Logged","middle":"In","last":"Profile"},"user2":{"username":"Developerdave","id":"34","first":"Dave","middle":"","last":"Ward"}}

返回的正确详细信息

我正在使用这个服务器端php

$json[] = array();
$com=mysqli_query($mysqli,"SELECT message_id,message_content,message_target,message_time,message_creator,message_throughurl FROM messages WHERE message_target='$user1_id' AND message_id > '$id' AND message_status=1 ORDER BY message_id DESC");
echo mysqli_error($mysqli);
$num = mysqli_num_rows($com);
if($num  && $user1_id){
    $json['num'] = $num;
}else{
    $json['num'] = 0;
}
$resultArr = mysqli_fetch_array($com);
$json['message_id'] = $resultArr['message_id'];
$json['message_content'] = $resultArr['message_content'];
$json['message_creator'] = $resultArr['message_creator'];
$json['message_target'] = $resultArr['message_target'];
$json['message_throughurl'] = $resultArr['message_throughurl'];
$json['message_time'] = $resultArr['message_time'];
mysqli_free_result($com);

$check = "SELECT * FROM user WHERE id=".$json['message_creator']."";
$check1 = mysqli_query($mysqli,$check);
$resultArr = mysqli_fetch_array($check1);
$json['username'] = ucfirst($resultArr['username']);
$json['id'] = $resultArr['id'];
$json['first'] = ucfirst($resultArr['first']);
$json['middle'] = ucfirst($resultArr['middle']);
$json['last'] = ucfirst($resultArr['last']);
mysqli_free_result($check1);

$check2 = "SELECT * FROM user WHERE id=".$json['message_target']."";
$check12 = mysqli_query($mysqli,$check2);
$resultArr2 = mysqli_fetch_array($check12);
$json2['username'] = ucfirst($resultArr2['username']);
$json2['id'] = $resultArr2['id'];
$json2['first'] = ucfirst($resultArr2['first']);
$json2['middle'] = ucfirst($resultArr2['middle']);
$json2['last'] = ucfirst($resultArr2['last']);
mysqli_free_result($check12);

$json = array(
    'user1' => $json,
    'user2' => $json2,
);
echo json_encode($json);
}

并尝试将其插入EX:

'+datamessage['user1.first']+' >>  '+datamessage['user2.first']+'

使用

success: function(datamessage){
if(datamessage.num>0){
 $("#notif_actual_textmessage-"+message_id).html('<div id="notif_actual_textmessage-'+datamessage['message_id']+'" class="notif_actual_textmessage"><img border=\"1\" src=\"userimages/cropped'+datamessage['message_creator']+'.jpg\" onerror=this.src=\"userimages/no_profile_img.jpeg\" width=\"40\" height=\"40\" ><br />'+datamessage['message_creator.first']+' >>  '+datamessage['message_target.first']+'<a class="markasreadmessage" href="'+datamessage['message_throughurl']+'">'+datamessage['message_content']+' </a><br /><abbr class="timeago" title="'+datamessage['message_time']+'">'+datamessage['message_time']+'</abbr><span class="newmessagescount">'+datamessage['nummessage']+'</span></div>');
}
}

开; y什么都没有插入我的div。所以我在某个地方出错了。有人可以说明我出错的地方。

非常感谢您的时间。谢谢

0 个答案:

没有答案