weixin_33696106 2014-09-06 11:40 采纳率: 0%
浏览 16

让两个用户都使用Ajax

How is it possible for me to get user one and user 2's information back through and Ajax request. Must I do two separate queries like so?

$check = "SELECT * FROM user WHERE id='$user1_id'";
$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='$user2_id'";
$check12 = mysqli_query($mysqli,$check2);
$resultArr2 = mysqli_fetch_array($check12);
$json['username'] = ucfirst($resultArr2['username']);
$json['id'] = $resultArr2['id'];
$json['first'] = ucfirst($resultArr2['first']);
$json['middle'] = ucfirst($resultArr2['middle']);
$json['last'] = ucfirst($resultArr2['last']);
mysqli_free_result($check2);

And when returned I have - '+datamessage['first']+' >> '+datamessage['first']+' problem is they swap positions in the server side depending on who's sent the message so user 2's name could be first or user1's could be first.

  • 写回答

2条回答 默认 最新

  • weixin_33735676 2014-09-06 11:43
    关注
    $check = "SELECT * FROM user WHERE id='$user1_id'";
    $check1 = mysqli_query($mysqli,$check);
    $resultArr = mysqli_fetch_array($check1);
    $json1['username'] = ucfirst($resultArr['username']);
    $json1['id'] = $resultArr['id'];
    $json1['first'] = ucfirst($resultArr['first']);
    $json1['middle'] = ucfirst($resultArr['middle']);
    $json1['last'] = ucfirst($resultArr['last']);
    mysqli_free_result($check1);
    
    $check2 = "SELECT * FROM user WHERE id='$user2_id'";
    $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($check2);
    
    $json = array(
        'user1' => $json1,
        'user2' => $json2,
    );
    
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题