怎样获取数据库更新的数据而不获取旧数据,求思路

WBOY
Release: 2016-06-06 20:09:29
Original
817 people have browsed it

用setInterval配合ajax每秒钟获取一次,怎样才能保证新的数据里不包含旧数据...

回复内容:

用setInterval配合ajax每秒钟获取一次,怎样才能保证新的数据里不包含旧数据...

后台处理ajax请求的时候重新去数据库里面查询一次就行了。如果你还涉及到页面上显示的数据,就先将页面上显示的旧数据清空,然后用ajax返回的新数据填充。

根據數據更新的時間來獲取,加個字段

你是要做什么,要每秒获取一次数据。如果用H5的话,可以用websocket

应该搞清新旧数据区别,时间区分?标识字段区分?

加了一个是否已读的字段,但是感觉这个方法只适合小规模的情况
怎样获取数据库更新的数据而不获取旧数据,求思路

<code class="php">if(!$_SESSION['lastid']){
  $sql = 'select * from shangqiang where xxx';
}else{
  $sql = 'select * from shangqian where xxx and id>'.$_SESSION['lastid'];
}
# fetch rows
$_SESSION['lastid'] = $lastid; // get it from fetch rows</code>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!