Guest User

Untitled

a guest
Oct 16th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. window.setInterval(loadNewPosts, 1000); //load simultaneous choice in 1 second
  2.  
  3. function loadNewPosts(){
  4. $.ajax({
  5. type: "GET",
  6. cache: false,
  7. dataType: "json",
  8. url: "latest.php",
  9. data: "current_id=" + current_id +"&nextType=" + nextType,
  10. success: function(data) {
  11.  
  12. for (var i = 0; i < data['array_x'].length; i++) {
  13. array_x.push(data['array_x'][i]);
  14. array_y.push(data['array_y'][i]);
  15. }
  16.  
  17. }
  18. });
  19. }
  20.  
  21. $servername = "";
  22. $username = "";
  23. $password = "";
  24. $dbname = "";
  25. $conn = mysqli_connect($servername, $username, $password, $dbname);
  26. // Check connection
  27. if (!$conn) {
  28. die("Connection failed: " . mysqli_connect_error());
  29. }
  30.  
  31. $current_id = intval($_GET['current_id']);
  32. $Type = (string)$_GET['nextType'];
  33. $sql = "SELECT * FROM `table` WHERE id > $current_id and Type='".$Type."'";
  34. $result = mysqli_query($conn, $sql);
  35. $array_x= [];
  36. $array_y= [];
  37.  
  38.  
  39. if (mysqli_num_rows($result) > 0) {
  40. // output data of each row
  41. while($row = mysqli_fetch_assoc($result)) {
  42. array_push($array_x,$row["X"]);
  43. array_push($array_y,$row["Y"]);
  44. }
  45. } else {
  46. echo "";
  47. }
  48.  
  49. mysqli_close($conn);
  50.  
  51. // return the posts as a JSON object
  52. header('Content-Type: application/json');
  53. $data=array(
  54. 'array_x' => $array_x,
  55. 'array_y' => $array_y
  56. );
  57. echo json_encode($data);
Add Comment
Please, Sign In to add comment