我不知道如何去做这件事,我正在建立一个聊天系统,所以我现在想要的是显示一个div与一个朋友的用户名,当朋友的名字是点击,就像facebook和我想要的用户的名字有一个链接到id,所以我可以使用它来识别哪个用户回声是div内的消息类型,请有人应该修复我的代码它是一个混乱的现在。
此代码显示的是我的friend_list
$list = "select friend_uid,friend_id from friend where user_id='$id' AND status='1'";
$friend = mysqli_query($conn,$list);
while($rowf = mysqli_fetch_assoc($friend)){
echo $rowf['friend_uid'].'<br>';
}
$friend_list = "select user_uid,user_id from friend where friend_id='$id' AND status='1'";
$res_friend = mysqli_query($conn,$friend_list);
while($row = mysqli_fetch_assoc($res_friend)){
?>
<nav id="chat_id" onclick="view()"><a href="#chat<?php echo $row['user_id']; ?>"><?php echo $row['user_uid'].'<br>';}?></a></nav>
<input type="text" placeholder="search for a friend">
</div>
</div>
<?php
}?>这是一个想要显示的div与朋友的用户名时,朋友的名字是点击
< div class="friend_chat">
<div id="chat" style="display:none;">
<label><?php echo $row['user_uid'];?></label>
<input type="text" placeholder="type a message">
<?php
?>
</div>
</div>
</div>
<script>
function view(){
var chat = document.getElementById('chat');
if(chat.style.display = "none"){
chat.style.display = "block";
}else{
chat.style.display = "none";
}
}
</script>发布于 2017-05-30 02:59:22
通过url传递用户的userid,如果不使用ajax,可以在聊天div中获取:
<a href=
"chat.php?uid=
<?php echo
$row["user_uid
"]; ?>"><?php
echo
$row["userna
me"]; ?></a>然后在聊天页面上执行以下操作:
<?php
if(isset($_GET["
uid
"])){
echo '<div
class=
"chat">'.$_GET[
"ui
d"].'</div>';
}
?>https://stackoverflow.com/questions/44247969
复制相似问题