我不知道该怎么做,正在构建聊天系统,所以我现在想要的是在朋友名称为单击时与朋友的用户名一起显示Div,就像Facebook的那样,我希望用户的名称具有指向ID的链接,因此我可以使用它来识别DIV内的用户Echo的消息类型,请某人应该修复我的代码,这是一团糟。<<<<<<<<<</p>
此代码显示为我的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>
如果您不使用AJAX:
<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>';
}
?>