douzhe9075 2013-08-17 12:25
浏览 62

如何从MySQL获取值并将其打印到PHP中

I'm working on a chat application with HTML, jQuery, PHP and MySQL. My program looks like this: on the left you have users bar, where you can find all the users (the program also displays whether user is online or not, but this I can handle). When you click a user from the list, it generates a draggable container div that looks like this:

<div class="container"><div class="head"></div><div id="conversation"></div></div>

Specification: the "head" class is used just to display the partner's avatar and toggle the "conversation" div on click.

My problem:

I think I will load the conversation inside the "conversation" div using AJAX and JavaScript so it will refresh the div without refreshing the page. The user will have multiple user conversations opened at a time, so I need an idea about how to identify which conversation to load in each div. I'm stuck here.

Optional: I want the user to see when the partner has seen the message, but I think I can display "Seen at DATE." when the conversation is set to visible. If you have another suggestion, feel free to explain.

Every information is taken from a MySQL database.

My PHP display function looks like this:

<?php

include_once('connect.php');

$you = $SESSION['user'];
$takeconversation = "SELECT * FROM conversations WHERE sender='$partner' AND receiver='$you' OR sender='$you' AND receiver='$partner'";
$dotake = mysqlquery($takeconversation);
?>

So $you is the $SESSION['user'], but I need to add an identifier to give a value to $partner, so $partner would have a different value for every conversation div.

  • 写回答

2条回答 默认 最新

  • dow46218 2013-08-18 08:02
    关注

    I recommend that you count the amount of conversations, create a <div> for each of those and append them to the main site. See How can I create and style a div using JavaScript? Give meaningful names like NUMBER_PARTNERNAME either to ID or name of the div so you can later address it easily.

    评论

报告相同问题?

悬赏问题

  • ¥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时遇到的编译问题