简体   繁体   English

消息传递会话php

[英]messaging Conversation php

i have created messaging system, on messages.php i want to show messages conversation wise and last message should be displayed but don't know the query as i'm new to php here is the database information 我已经在messages.php上创建了消息传递系统,我想向消息显示对话,并且应该显示最后一条消息,但是不知道查询,因为我是php的新手,这是数据库信息

  table:conversation_chat table2:chat conversation_id: primary unique id: primary unique from: conversation_id: to: from_user: time: to_user: message: subject: 

Please if Someone can help me in this 如果有人可以帮助我

 <?php

  $req3 = mysql_query("SELECT * FROM `conversation_chat` WHERE 
  `user_to`='$userid1'");
 $hy= mysql_fetch_array($req3);

  $convo = $hy['conversation_id'];

  if(mysql_num_rows($req3)!=0){

  $req4 = mysql_query("SELECT * FROM `chat` WHERE `to`='$userid1' AND  

  `conversation_id`='$convo'");
      while($dn1 = mysql_fetch_array($req4))
   { 
  ?>

 <td><img alt="example image" src="avatar.png"> &nbsp; &nbsp; <a 
 href="read?id=<?php echo $dn1['id']; ?>"><?php echo
 htmlentities($dn1['from'], ENT_QUOTES, 'UTF-8'); ?></a></td>



                  <td><span class="label vd_bg-green append-icon">

 <?php  
 echo $dn1['subject']; ?></span></td>
                  <td style="width:80px" class="text-right"> 

 <strong><?php echo timeAgo($dn1['time']); ?></strong></td><td 

 style="width:80px" class="text-right">
 <?php echo '<a 
 href="mdelete.php?id='. $dn1['id'] .'">Delete</a>'; ?></td>
                </tr>
                <?php
 }}else{ echo "No new messages";}
 ?>

Okay, you just edited your database informations. 好的,您刚刚编辑了数据库信息。 So now i understand how your database is. 现在,我了解您的数据库如何。

You must add a "time" column with DATETIME type in chat2" 您必须在chat2中添加DATETIME类型的“时间”列”

SELECT * 

FROM `chat` 

WHERE `to`='$userid1' 

AND  

  `conversation_id`='$convo'    

ORDER BY time DESC //Change the order from last to older

If you only want the last message, and if its a MySQL database, you can add 如果只需要最后一条消息,并且它是一个MySQL数据库,则可以添加

LIMIT 1

If I understand your question correctly, you want to display one and only one message. 如果我正确理解您的问题,则只想显示一条消息。 Namely the latest? 即最新?

If that is true change your query from 如果是这样,请从

SELECT * FROM `chat` ...

To

SELECT *, max(date) FROM `chat` ...

Select 选择

<?php

  $req3 = "SELECT DISTINCT conversation_id,column_name FROM `conversation_chat` WHERE 
  `user_to`='$userid1' ORDER BY conversation_id desc";
$query=mysql_query($req3);
$num=mysql_num_rows($req3);
 $hy= mysql_fetch_array($req3);

  $convo = $hy['conversation_id'];

  if($num!=0){

  $req4 = mysql_query("SELECT DISTINCT id,column_name FROM `chat` WHERE `to`='$userid1' AND  

  `conversation_id`='$convo' ORDER BY id desc ");
      while($dn1 = mysql_fetch_array($req4))
   { 
  ?>

 <td><img alt="example image" src="avatar.png"> &nbsp; &nbsp; <a 
 href="read?id=<?php echo $dn1['id']; ?>"><?php echo
 htmlentities($dn1['from'], ENT_QUOTES, 'UTF-8'); ?></a></td>



                  <td><span class="label vd_bg-green append-icon">

 <?php  
 echo $dn1['subject']; ?></span></td>
                  <td style="width:80px" class="text-right"> 

 <strong><?php echo timeAgo($dn1['time']); ?></strong></td><td 

 style="width:80px" class="text-right">
 <?php echo '<a 
 href="mdelete.php?id='. $dn1['id'] .'">Delete</a>'; ?></td>
                </tr>
                <?php
 }}else{ echo "No new messages";}
 ?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM