我已经创建了一个聊天框使用php.its流畅的works.but我不知道什么时候新的消息插入我的mysql database.How我能知道吗?我已经试着在这个code.but下面,它总是给我返回新的消息。
$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";}发布于 2016-10-26 17:57:55
在插入到数据库之后,mysqli应该返回受影响的行数,您可以用它来了解数据库中是否插入了新数据。
该数字存储在$mysqli->affected_rows中
示例:
<?php
$c = new mysqli("server","username","password","database");
$c->query("insert into table(column1,column2,column3) values('data','data','data')");
echo $c->affected_rows; // returns the affected rows
?>https://stackoverflow.com/questions/40259000
复制相似问题