0
<?php
$host= "localhost";
$user= "xxxxxx";
$pass= "xxxx";
$db="xxxxxxx";

$connect= mysql_connect($host,$user,$pass);
if (!$connect)die ("Cannot connect!");
mysql_select_db($db, $connect);

$result = mysql_query("
    SELECT
        *
    FROM
        values
");

if($result){
    while($row = mysql_fetch_array($result, MYSQL_ASSOC)){

$url = $row['value'];
echo '<li><iframe src="http://xxxxxxx.xxxx/xxxx.php?value='.$url.'" width="300" height="100" scrolling="no" frameBorder="0""></iframe></li>';
}
}
?>

this is my php code I am using to get values from database. I want to use a time delay in each of the value.

like

 http://xxxxxxx.xxxx/xxxx.php?value='.$url.'
wait 5 sec
http://xxxxxxx.xxxx/xxxx.php?value='.$url.'
wait 5 sec

and so on.

Is there any way I can do that.

Thanks.

Vinay
  • 57
  • 1
  • 11

1 Answers1

0
  1. wrong answer: use sleep(5) inside while().

  2. right answer:

a) you should not use mysql_* functions

b) if you need a delay, get all rows, then output them one by one using JS.

OR:

c) again, using JS and ajax, query for new row every 5 seconds

If you'll stick to wrong answer, your script will die of timeout at ~6th row (in default php install)

You should understand client/server architecture better:

mysql query and your php-code is a server-side, it will not return any output to browser (your visitor), until its end, and you don't want your visitors to wait 30 or 300 seconds for the server to reply.

so only option you have is: query for new image every 5 seconds, or query them all and iterate over them.

There are many jquery/javascript tutorials on that subject.

strangeqargo
  • 1,276
  • 1
  • 15
  • 23
  • http://stackoverflow.com/questions/5687600/jquery-call-ajax-every-10-seconds, google jquery/ajax/setinterval/mysql from there. – strangeqargo May 16 '16 at 18:37