Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- window.setInterval(loadNewPosts, 1000); //load simultaneous choice in 1 second
- function loadNewPosts(){
- $.ajax({
- type: "GET",
- cache: false,
- dataType: "json",
- url: "latest.php",
- data: "current_id=" + current_id +"&nextType=" + nextType,
- success: function(data) {
- for (var i = 0; i < data['array_x'].length; i++) {
- array_x.push(data['array_x'][i]);
- array_y.push(data['array_y'][i]);
- }
- }
- });
- }
- $servername = "";
- $username = "";
- $password = "";
- $dbname = "";
- $conn = mysqli_connect($servername, $username, $password, $dbname);
- // Check connection
- if (!$conn) {
- die("Connection failed: " . mysqli_connect_error());
- }
- $current_id = intval($_GET['current_id']);
- $Type = (string)$_GET['nextType'];
- $sql = "SELECT * FROM `table` WHERE id > $current_id and Type='".$Type."'";
- $result = mysqli_query($conn, $sql);
- $array_x= [];
- $array_y= [];
- if (mysqli_num_rows($result) > 0) {
- // output data of each row
- while($row = mysqli_fetch_assoc($result)) {
- array_push($array_x,$row["X"]);
- array_push($array_y,$row["Y"]);
- }
- } else {
- echo "";
- }
- mysqli_close($conn);
- // return the posts as a JSON object
- header('Content-Type: application/json');
- $data=array(
- 'array_x' => $array_x,
- 'array_y' => $array_y
- );
- echo json_encode($data);
Add Comment
Please, Sign In to add comment