I want to send the result of an SQL query which is a PHP variable to the index file. Here's from the PHP I want to send from:
$result = mysqli_query($conn, $sql);
$remaining = array();
while($row = mysqli_fetch_array($result)){
array_push($remaining, $row['_id']);
}
echo json_encode($remaining);
?>
<script>
$.ajax({
url: "index.php",
data: {result: result},
dataType: "json",
success: function(result){
}});
</script>
Here is where I want to use the code:
$var_value = $_GET['remaining'];
$values = implode(", ", $var_value);
$sql = "SELECT *
FROM `species`
WHERE `_id` IN (".$valus.") ";
$results = mysqli_query($conn, $sql);
I have tried many methods, running a second ajax call within one already running since the $remaining variable is sent back to a javascript using ajax. $_cookies doesn't work for my webserver. So this seems the best solution. Can anyone see what is going wrong?
SELECT * FROM art WHERE _id IN ( [$sql from first example] )?