0

I have an array with 4 rows, I Want to show them one by one, But only one and with an Interval.

Like: Row1 show for 5secs -> Row2 show for 5secs -> Row3 show for 5secs -> Row4 show for 5secs

I tried this, but that is not working. It loads much time and than showing only one and doing nothing more.

$count = mysqli_num_rows($result) -1;
 for ($i=0; $i < $count; $i++) { 
    $random = rand(0, $count);
    echo json_encode($data[$random]);
    unset($data[$random]);
    $count -= 1;
    sleep(5);
}
2
  • $count -= 1 and $i++ are in conflict .. .. you should use another type of loop .. try using a while (count($data)) > 0 Commented Oct 13, 2017 at 19:27
  • If you want timed output you will need to look into the flush functions. Commented Oct 13, 2017 at 19:31

1 Answer 1

0

I think the solution could be to simply to deliver all the data in PHP to a javascript client, and have the client simply show the information using a simple setTimeout function or perhaps using CSS animation.

similar to this:

Using CSS for fade-in effect on page load

or perhaps this:

https://www.sitepoint.com/jquery-settimeout-function-examples/

that you can get rid of the PHP sleep() call.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.