unknown87 Posted November 21, 2008 Share Posted November 21, 2008 hi i want to set up a time stamp to count up to 18,000 seconds. This is going to happen every week at a specific time. I will be using a cron job to start the script. In my database, i have a column which includes values, for example: id 1 has a value of 30 id 2 has a value of 60 id 3 has a value of 90 ... and so on. So when the timestamp reaches 30 seconds, i want it to display id 1. when the count reaches to 60 seconds, i want id 1 & 2 to be displayed to the browser and so on. I want to know if this is possibe, if it is could someone please help me and get me started. Thanks in advance. Quote Link to comment Share on other sites More sharing options...
gevans Posted November 21, 2008 Share Posted November 21, 2008 You might have to try and explain this better. If you're using a cronjob your pages wouldn't be showing in a browser. Quote Link to comment Share on other sites More sharing options...
unknown87 Posted November 21, 2008 Author Share Posted November 21, 2008 never knew that - i have never worked with crons before. If i dont use crons, how else can i get the timestamp to start count? Quote Link to comment Share on other sites More sharing options...
gevans Posted November 21, 2008 Share Posted November 21, 2008 I'm still not sure what you want to do, a timestamp won't 'count' it's just a 'stamp' for a certain place in time Quote Link to comment Share on other sites More sharing options...
unknown87 Posted November 21, 2008 Author Share Posted November 21, 2008 basically, i'm in the process of making a online cricket management game. I want the games to look like they are being played live but everything has already been calculated and stored the database. That's why i need it to display the data from the database every thirty seconds. Been working on this for over two weeks with no luck at all but i know some how its possible but can't find the solution. Quote Link to comment Share on other sites More sharing options...
gevans Posted November 21, 2008 Share Posted November 21, 2008 I think I know what you mean, and I think I've got an idea, but it's a long one to explain but I'll try.... Firstly add another field to your database table 'last_used'. last_used will hold a timestamp from the last time it was used. Every time a page is visited query last_used. If the current time's timestamp is more than 30 seconds ahead of the last highest go to the next id (update that row with the current time stamp) If that doesn't make sense I can try again Quote Link to comment Share on other sites More sharing options...
unknown87 Posted November 21, 2008 Author Share Posted November 21, 2008 i dont understand the last bit Quote Link to comment Share on other sites More sharing options...
gevans Posted November 21, 2008 Share Posted November 21, 2008 id 1 has a value of 30 timestamp = 100000 id 2 has a value of 60 timestamp = 99940 id 3 has a value of 90 timestamp = 99970 I'm aware they're not real timestamps, I'm just making them smaller for the example; Everytime a page loads do the following $query = "SELECT * FROM table ORDER BY timestamp DESC LIMIT 2"; This will get the id with the biggest timestamp first (closest to current time) Then get the details of the first result and check the following; if(timestamp_now-timestamp_from_table > 30) if the statement returns true go to the next row of the table. Use this information on your page and update the timestamp to the current one. So working off the details at the start of this reply, if the current timestamp was 100020 then the if statement would be false and you'd use the first set of results. If it was 100040 the if statement would return true and you'd use the second row (id 2) and update id 2's timestamp = 100040 Quote Link to comment Share on other sites More sharing options...
unknown87 Posted November 21, 2008 Author Share Posted November 21, 2008 I'll give it a try - i'll let you know if I run into any problems. I appreciate all your help, thanks Quote Link to comment Share on other sites More sharing options...
redarrow Posted November 21, 2008 Share Posted November 21, 2008 would this work................ <?php $sql="select sum(sum_field) as x from table_name"; $res=mysql_query($sql)or die(mysql_error()); while($data=mysql_fetch_assoc($res)){ if($data['x']=="18.000"){ $time_now=date('s'); for($t=31; $t<59; $t++){ if($time_now==$t){ for($ss=0; $ss<count($data['x']); $ss++){ $ssum=(60)*2; } if($data['sum_field']==$ssum){ $sq2="select * from table_name where sum_field='".$data['sum_field']."'"; $res1=mysql_query($sql)or die(mysql_error()); while($data1=mysql_fetch_assoc($res)){ echo $data1['id']; } } } } } } ?> Quote Link to comment Share on other sites More sharing options...
gevans Posted November 21, 2008 Share Posted November 21, 2008 That seems to make sense... Not 100% if mine will, but it seemed to make sense. Quote Link to comment Share on other sites More sharing options...
redarrow Posted November 21, 2008 Share Posted November 21, 2008 done this for fun works ok now and then..... it shows pictures and delays via the time function then starts agin............... give it a go was a good lath creating...... might work might not theo.......... <?php session_start(); $sql="select sum(sum_field) as x from table_name"; $res=mysql_query($sql)or die(mysql_error()); while($data=mysql_fetch_assoc($res)){ $d=$data['x']; } if($d=="18.000"){ header('Refresh: 29; url='.$_SERVER['PHP_SELF'].''); $time_now=date('s'); for($t=30; $t<59; $t++){ if($time_now==$t){ for($ss=0; $ss<$d; $ss++){ if($_SESSION['ssum']<1060){ if(!$_SESSION['ssum']){ header('Refresh: 2; url='.$_SERVER['PHP_SELF'].''); $_SESSION['ssum']=60; }else{ $_SESSION['ssum']=$_SESSION['ssum']+60; } }else{ unset($_SESSION['ssum']); } } }else{ if(!$time_now==$t){ unset($_SESSION['ssum']); session_destroy(); die(); } } } } $url=array("http://www.thereddragonhood.com/images/rabbit.jpg","http://www.naturephoto-cz.com/photos/others/wild-rabbit-41946.jpg","http://www.bunny-rabbits.com/rabbits.jpg"); shuffle($url); if($_SESSION['ssum']){ $img= "<img width='100' height='100' src='".$url[0]."'>"; }else{ $img=" "; } echo $img; ?> Quote Link to comment Share on other sites More sharing options...
unknown87 Posted November 21, 2008 Author Share Posted November 21, 2008 <?php session_start(); $connection = mysql_connect("localhost","root",******); if (!$connection) { die("Database connection failed: " . mysql_error()); } $db_select = mysql_select_db("ocmg",$connection); if (!$db_select) { die("Database selection failed: " . mysql_error()); } $sql="SELECT runs(time) AS x FROM runs"; $res=mysql_query($sql)or die(mysql_error()); while($data=mysql_fetch_assoc($res)){ $d=$data['x']; } if($d=="18.000"){ header('Refresh: 29; url='.$_SERVER['PHP_SELF'].''); $time_now=date('s'); for($t=30; $t<59; $t++){ if($time_now==$t){ for($ss=0; $ss<$d; $ss++){ if($_SESSION['ssum']<1060){ if(!$_SESSION['ssum']){ header('Refresh: 2; url='.$_SERVER['PHP_SELF'].''); $_SESSION['ssum']=60; }else{ $_SESSION['ssum']=$_SESSION['ssum']+60; } }else{ unset($_SESSION['ssum']); } } }else{ if(!$time_now==$t){ unset($_SESSION['ssum']); session_destroy(); die(); } } } } $url=array("http://www.thereddragonhood.com/images/rabbit.jpg","http://www.naturephoto-cz.com/photos/others/wild-rabbit-41946.jpg","http://www.bunny-rabbits.com/rabbits.jpg"); shuffle($url); if($_SESSION['ssum']){ $img= "<img width='100' height='100' src='".$url[0]."'>"; }else{ $img=" "; } echo $img; ?> I'm getting this error displayed to the browser: FUNCTION ocmg.runs does not exist SELECT score(time) AS x FROM runs - score = this column has all the runs, i want to display to the browser - time = this column has the 30, 60, 90... values in them - runs = table name I can't see where I'm going wrong here. Anyone know why I'm getting this error? Quote Link to comment Share on other sites More sharing options...
gevans Posted November 21, 2008 Share Posted November 21, 2008 I'm getting this error displayed to the browser: FUNCTION ocmg.runs does not exist SELECT score(time) AS x FROM runs The SELECT code is written different in your full script and at the bottom there, SELECT runs(time) AS x FROM runs //and SELECT score(time) AS x FROM runs Quote Link to comment Share on other sites More sharing options...
unknown87 Posted November 21, 2008 Author Share Posted November 21, 2008 sorry - i posted the wrong one, in the full script its meant to be "score" not "runs". the error is displaying when i got "score" in the script. Quote Link to comment Share on other sites More sharing options...
gevans Posted November 21, 2008 Share Posted November 21, 2008 shouldn't it be; SELECT sum(score) AS x FROM runs Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.