当前位置: 代码迷 >> PHP >> php jquery 无刷新评说
  详细解决方案

php jquery 无刷新评说

热度:282   发布时间:2016-04-28 20:20:39.0
php jquery 无刷新评论

php jquery 无刷新评论

刷新后删除一个小时前的记录

?

php jquery 无刷新评论
演示

?

?XML/HTML Code

?
  1. <?php??
  2. ??
  3. define('INCLUDE_CHECK',1);??
  4. require?"functions.php";??
  5. require?"conn.php";??
  6. ??
  7. ??
  8. //?remove?tweets?older?than?1?hour?to?prevent?spam??
  9. mysql_query("DELETE?FROM?add_delete_record?WHERE?id>1?AND?updatetime<SUBTIME(NOW(),'0?1:0:0')");??
  10. ??????
  11. //fetch?the?timeline??
  12. $q?=?mysql_query("SELECT?*?FROM?add_delete_record?ORDER?BY?ID?DESC");??
  13. ??
  14. $timeline='';??
  15. while($row=mysql_fetch_assoc($q))??
  16. {??
  17. ????$timeline.=formatTweet($row['text'],$row['updatetime']);??
  18. }??
  19. ??
  20. //?fetch?the?latest?tweet??
  21. $lastTweet?=?'';??
  22. ??
  23. ?>??
  24. ??
  25. <!DOCTYPE?html?PUBLIC?"-//W3C//DTD?XHTML?1.0?Transitional//EN"?"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">??
  26. <html?xmlns="http://www.w3.org/1999/xhtml">??
  27. <head>??
  28. <meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8"?/>??
  29. <title>php?jquery?无刷新评论?www.freejs.net</title>??
  30. ??
  31. <link?rel="stylesheet"?type="text/css"?href="demo.css"?/>??
  32. <script?type="text/javascript"?src="../../js/jquery-1.9.1.min.js"></script>??
  33. <script?type="text/javascript"?src="script.js"></script>??
  34. ??
  35. ??
  36. </head>??
  37. ??
  38. <body>??
  39. ??
  40. <div?id="twitter-container">??
  41. <form?id="tweetForm"?action="submit.php"?method="post">??
  42. ??
  43. <span?class="counter">140</span>??
  44. <label?for="inputField">请留言测试</label>??
  45. ??
  46. <textarea?name="inputField"?id="inputField"?tabindex="1"?rows="2"?cols="40"></textarea>??
  47. <input?class="submitButton?inact"?name="submit"?type="submit"?value="提交"?disabled="disabled"?/>??
  48. ??
  49. ??
  50. <div?class="clear"></div>??
  51. ??
  52. </form>??
  53. ??
  54. <h3?class="timeline">Freejs.net</h3>??
  55. ??
  56. <ul?class="statuses"><?php?echo?$timeline?></ul>??
  57. ??
  58. ??
  59. </div>??
  60. ??
  61. </body>??
  62. </html>??

?functions.php

?

PHP Code
  1. <?php??
  2. ??
  3. if(!defined('INCLUDE_CHECK'))?die('You?are?not?allowed?to?execute?this?file?directly');??
  4. ??
  5. function?formatTweet($tweet,$updatetime)??
  6. {??
  7. ??
  8. ??
  9. ????$tweet=htmlspecialchars(stripslashes($tweet));??
  10. ????$flag?=?mt_rand(1,9);??
  11. ??
  12. ????return'?
  13. ????<li>?
  14. ????<a?href="#"><img?class="avatar"?src="img/lito_s-ido_0'.$flag.'.png"?width="48"?height="48"?/></a>?
  15. ????<div?class="tweetTxt">?
  16. ????<strong><a?href="#">demo</a></strong>?'.?preg_replace('/((?:http|https|ftp):\/\/(?:[A-Z0-9][A-Z0-9_-]*(?:\.[A-Z0-9][A-Z0-9_-]*)+):?(\d+)?\/?[^\s\"\']+)/i','<a?href="$1"?rel="nofollow"?target="blank">$1</a>',$tweet).'?
  17. ????<div?class="date">'.strtotime($updatetime).'</div>?
  18. ????</div>?
  19. ????<div?class="clear"></div>?
  20. ????</li>';??
  21. ??
  22. }??
  23. ??
  24. ?>??

submit.php

PHP Code
  1. <?php??
  2. ??
  3. define('INCLUDE_CHECK',1);??
  4. require?"functions.php";??
  5. require?"conn.php";??
  6. ??
  7. ??
  8. if(ini_get('magic_quotes_gpc'))??
  9. $_POST['inputField']=stripslashes($_POST['inputField']);??
  10. ??
  11. ??
  12. ??
  13. $_POST['inputField']?=?mysql_real_escape_string(strip_tags($_POST['inputField']),$lr);??
  14. ??
  15. if(mb_strlen($_POST['inputField'])?<?1?||?mb_strlen($_POST['inputField'])>140)??
  16. die("0");??
  17. ??
  18. mysql_query("INSERT?INTO?add_delete_record?SET?text='".$_POST['inputField']."',updatetime=NOW()");??
  19. ??
  20. if(mysql_affected_rows($lr)!=1)??
  21. die("0");??
  22. ??
  23. echo?formatTweet($_POST['inputField'],time());??
  24. ??
  25. ?>??
  26. ?


原文地址:http://www.freejs.net/article_biaodan_88.html

  相关解决方案