<?php $array = $_POST['list']; $userID = $_SESSION['log']; $result = null; function getData($userID, $array){ function compare($a, $b){ if ($a === $b) { return 0; } return ($a > $b)? 1:-1; } try{ $stmt = null; $conn = new PDO("mysql:host=localhost;dbname=list", 'root', ''); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $stmt = $conn->query("SELECT noteText FROM notes WHERE userID='$userID'"); $row = $stmt->fetch(); $result = array_diff_uassoc($row, $array, 'compare'); foreach ($result as $note) { $stmt = $conn->prepare("INSERT INTO notes (noteText, userID) VALUES (:note, '$userID')"); } $conn = null; } catch(PDOException $e) { return false; $e->getMessage(); } } getData($userID,$array); ?>
A tu kod js
function synchronize(){ var listArray = []; if (typeof li[0] != 'undefined') { for (let i = 0; i< li.length; i++){ listArray[i] = li[i].textContent; } $.post( "scripts/synchronize.php", { list: listArray }, function(data){ let a = Object.keys(data).map(function(key) { return data }); alert(a); } ); } }