This is my Ajax POST
request:
function getRelated() {
var elements = (document.getElementsByClassName('escashare'));
var query = [];
for(var i=0;typeof(elements[i])!='undefined';query.push(elements[i++].getAttribute('data-id')));
$.ajax({
type: "POST",
url: baseUrl+"/requests/get_related.php",
data: "query="+query+'&_token='+_token,
cache: false,
success: function(html){
$('#main-content').append(html);
}
});
}
So basically I POST
an array of int
numbers like:
["326", "311", "312", "313", "314", "316", "317", "318", "319", "15", "9", "87"]
When in my PHP I implode
the query
array it gives me NULL
but why?
$newQuery = implode(',', $QueryFromPost);
var_dump($newQuery); //NULL
EDIT
I need to use it for:
$query = $this->db->query(sprintf("SELECT * FROM `posts` WHERE `id` IN ('%s')", $newQuery));
while($result = $query->fetch_assoc()) {
$rows[] = $result;
}
if(!empty($rows)) {
foreach($rows as $row) {
$output .= '<div class="stage">'.$row['id'].'</div>';
}
}
return $output;