Advertisement
Guest User

Untitled

a guest
Mar 2nd, 2015
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. if($_REQUEST['tutid'] && $_REQUEST['cid']){
  2. //make array to cid to get id
  3. foreach($_REQUEST['cid'] as $key => $value){
  4.  
  5. $res = mysqli_query($dbh,"SELECT * FROM test WHERE id =".$value." AND page_id=".$_REQUEST['tutid']." ORDER BY id DESC LIMIT 1") or die(mysqli_error($dbh));
  6.  
  7. $rows = mysqli_fetch_assoc($res);
  8.  
  9. $row[] = array_map('utf8_encode', $rows); //line 80
  10. $data = array();
  11.  
  12. $data['id'] = $rows['id'];
  13. $data['username'] = $rows['username'];
  14. $data['description'] = $rows['description'];
  15. //etc all
  16.  
  17. //do something
  18.  
  19. if (!empty($data)) {
  20. echo json_encode($data);
  21. flush();
  22. exit(0);
  23. }
  24. }
  25. }
  26.  
  27. if (!empty($rows)) {
  28. $row[] = array_map('utf8_encode', $rows);
  29. }
  30.  
  31. <div class="case" data-post-id=".$id."></div>
  32. <div class="case" data-post-id=".$id."></div>
  33. // etc more
  34.  
  35. <script type="text/javascript" charset="utf-8">
  36.  
  37. var CID = [];
  38. $('div[data-post-id]').each(function(i){
  39. CID[i] = $(this).data('post-id');
  40. });
  41.  
  42. function addrep(type, msg){
  43. CID.forEach(function(id){
  44. $("#newreply"+id).append("<div class='"+ type +""+ msg.id +"'><ul>"+ msg.description +"</ul></div>");
  45. });
  46. }
  47. var tutid = '<?php echo $tutid; ?>';
  48. function waitForRep(){
  49. $.ajax({
  50. type: "GET",
  51. url: "/server.php",
  52. cache: false,
  53. data: {
  54. tutid : tutid,
  55. // this way array containing all ID's can be sent:
  56. cid : CID
  57. },
  58. timeout:15000,
  59. success: function(data){
  60. addrep("postreply", data);
  61. setTimeout(
  62. waitForRep,
  63. 15000
  64. );
  65. },
  66. error: function(XMLHttpRequest, textStatus, errorThrown){
  67. setTimeout(
  68. waitForRep,
  69. 15000);
  70. }
  71. });
  72. }
  73.  
  74.  
  75. $(document).ready(function(){
  76. waitForRep();
  77. });
  78. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement