View Full Version : Times Problem

03-15-2008, 05:00 PM
So i want to select information from database and after 20 second when file has opened write another information in that row.

i wrote such code:

$select = mysql_query("SELECT * FROM news WHERE id=5");
$time = time();
$insert mysql_query("INSERT INTO news SET last_time = '$time'");
$time2 = time() + 20;
$last_time = mysql_query("SELECT last_time FROM news WHERE id = 5 ");
if($time2 > $last_time){
$addshows = mysql_query("INSERT INTO news SET shows = 2");
but it is not working how i can to work this script? or is another way to make such script?

03-15-2008, 05:14 PM
Because PHP is server side as far as im aware this is not possible, the server reads the php and then executes it. There is not wait command, therefore the best way to do this would be with HTML.

If you google HTML refresh it should come up with something. I cant remember the exact code and I cant get to it here. Post back if you can or cannot find it and if not I will post it when I get home.

03-15-2008, 06:11 PM
Well, you could use flush(); to send the output and sleep(20); to wait, but PHP is not the best way to do this because you'll either hit the loading time limit or you'll have to circumvent it, and that will cause more problems than solutions. If the information is static you can load it into Javascript vars and then use it to display them every 20 seconds.