I have my json being passed to the php file as follows.
JAVASCRIPT
$.ajax({
url: "/gallerytest/getimages.php",
type: "POST",
dataType: "json",
data: {
imagesArray: imageArray.itemList,
action: "load"
},
success: function(imagesArray) {
for (var i = 0; i < imagesArray.length; i++) {
console.log('image ' + imagesArray[i]["src"]);
}
}
});
With the imagesArray being captured in the php file, I want to put it into an array. In my php I have this so far:
PHP
if(isset($_POST['action']) && !empty($_POST['action'])) {
$action = $_POST['action'];
switch($action) {
case "test" : test();break;
case "load" : load();break;
// ...etc...
}
}
function load(){
$imagesArray = $_POST['imagesArray'];
$images = json_decode($imagesArray, true);
$imagesArr = array();
for ($i = 0; $i < count($images); $i++){
$image = array(
"src" => $images[$i]
);
$imagesArr[] = $image;
}
echo json_encode($imagesArr);
}
I am passing the array back for testing purposes where the javascript outputs the src of each element.
The ultimate goal which I would like help on too, should it not go beyond the call of duty, is in an SQL statement capture more images where the src does not match. In essence:
SELECT * FROM images WHERE id_image NOT IN (imagesArray) ORDER BY rand() LIMIT 12