12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 | <?php$db = mysqli_connect('localhost', '用户名', '密码', '数据库名') or exit('Unable to connect to MySQL.');mysqli_query($db, 'SET NAMES UTF8');?><!doctype html><html><head><meta charset="utf-8" /><title>微信墙</title><style>#msgBox div { padding: 19px; margin-bottom: 20px; background: #f5f5f5; border: 1px solid #e3e3e3; -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px; -webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,0.05); -moz-box-shadow: inset 0 1px 1px rgba(0,0,0,0.05); box-shadow: inset 0 1px 1px rgba(0,0,0,0.05);}</style></head><body><div id="msgBox"><?php$wxQuery = 'SELECT * FROM message ORDER BY recordID DESC LIMIT 20';$wxResult = mysqli_query($db, $wxQuery);while ($wxRow=mysqli_fetch_assoc($wxResult)) { $lastID or $lastID = $wxRow['recordID']; $content = $wxRow['content']; echo '<div>',$content,"</div>/n";}$lastID = (int)$lastID;?></div> <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.3.min.js"></script><script>var lastID = <?php echo $lastID; ?>;function getMessages() { $.ajax({ url : '/message.php?lastID=' + lastID + '&v=' + (new Date()/1), success : function(xml){ $(xml).find('message').each(function() { if ($(this).attr('recordID') > lastID) { var message = $(this).text(); message = '<div>' + message + '</div>'; $(message).prependTo('#msgBox').hide().slideDown('slow'); lastID = $(this).attr('recordID'); } }); } }); window.setTimeout(getMessages, 5000);}getMessages();</script></body></html> |