how to set timer of setInterval on jquery from the record of mysql database? here i have a table on mysql database with following columns
---------+-------------+-------------
| ID + slidename + displayfor |
---------+-------------+-------------
| 1 + slide 1 + 3000 |
| 2 + slide 2 + 10000 |
-------------------------------------
i am using one page scroll with fixed timer on setInterval. i want to replace the fixed timer with the above displayfor data
<?php
$getslides="select * from slides";
$slides=$db->query($getslides);
$countRows = $db->num_rows($slides);
$c=0;
while($setslides=$db->fetch_object($slides))
{
$c++;
?>
<script>
var x=0;
var last = <?php echo $countRows; ?>;
sliding = function(){
x++;
if(x<=last)
{
$("a[data-index="+x+"]").trigger("click");
$('#'+x).trigger('click');
}
else
{
x=0;
$('#'+x).trigger('click');
}
}
setInterval(sliding, 5000);
</script>
<?php
}
?>
i want to change setInterval's 5000 to the record of displayfor. is there any method to change the interval time with the database record
Your Javascript is in a block of HTML that is generated via PHP. Nice and simple, as we have access to PHP variables (and your <script>
tag is within a while
loop), we can access the $setslides
object and echo out the displayfor variable using an embedded PHP script.
setInterval(sliding, <?php echo $setslides->displayfor; ?>);