【发布时间】:2016-10-26 09:49:58
【问题描述】:
我已经使用 php 创建了一个聊天框。它运行顺利。但我不知道新消息何时插入我的 mysql 数据库。我怎么知道?我已经尝试过低于此代码。但它总是给我返回新消息。
$initialCounter = 0;
$count_query = "select * from `message` where `receiver_id` = '$sender_id' AND `sender_id` = '$rid' order by `id` desc";
$count_query_res = $conn->query($count_query);
$countMsg = $count_query_res->num_rows;
$initialCounter += $countMsg;
$msgcounter = $initialCounter + $countMsg;
if($initialCounter<$msgcounter){ echo "new message";}
【问题讨论】:
-
您计算了
$msgcounter = $initialCounter + $countMsg;,然后想知道为什么$msgcounter > $initialCounter紧随其后一行?如果$countMsg > 0与$countMsg相差无几,它总是会更大。目前还不清楚您要做什么。您可能应该将新计数与您存储在某处的值进行比较。 -
@Solarflare 在这里选择查询用于消息读取。但是我如何理解可用的新消息?有什么想法吗?