This is working fine, but I'm trying to find a good solution to stop Javascript setInterval
when all responses has been fetched from a database through Ajax.
A for loop inside a for loop could work, I think?!
HTML:
<!-- code is simplefied, problem is not about syntax, but the way to do it. -->
SELECT id FROM database WHERE x=y
$rows = countrows(); //know how much different output there is
for(i=1; i <= rows; i++) // Show div everytime there's a response
{
$data-> fetch();
<div id="<?php echo "div" . $i;?>">
<?php echo 'id' . $data['id']; ?>
</div>
}
Let's say we have 3 responses from database, and we have 3 div
s with 3 different id
s.
Javascript:
setInterval(getResponse(), 1000); //execute function every second
getResponse()
{
for(i=1; i <= $rows; i++)
{
//Here is the problem
//Stop getResponse function execution when all responses has been taken
if(response[i] && reponse[i] && ...)
{
//Stop function
}
//Select id . $data['id'] WHERE div . $i = i;
// GET VARIABLE FROM DATABASE WHERE ID = 'id' . $data['id'];
if(response)
{
//INSERT THIS VARIABLE IN THE RIGHT DIV.
$response[i] = true;
}
}
}