Jump to content

timestamp


unknown87

Recommended Posts

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.

 

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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'];	
    }	
  }
    }
    
    }
     }
  }

?>

Link to comment
Share on other sites

 

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;
?>

Link to comment
Share on other sites

<?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?

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.