开发者

how to save a javascript rendered countdown timer to mysql using PHP?

开发者 https://www.devze.com 2022-12-20 10:45 出处:网络
can someone please tell me how to save a javascript rendered countdown timer to mysql db using PHP ? e.g

can someone please tell me how to save a javascript rendered countdown timer to mysql db using PHP ? e.g I have this button, that when someone clicks it, the countdown appears and starts counting.

so yeah, that's my problem, what's the best way to do in order to ensure that - the exact date/time(in unix format) the button got clicked will be saved in db? is this possible with PHP ?

// this is the PHP and HTML

<?php foreach($task->result() as $row): ?> 
  <tr> 
    <td><a title="<?php echo $row->descr; ?>" 
           href="#"><?php echo $row->title; ?>&l开发者_StackOverflow中文版t;/a>
    </td> 
    <td><input type = "button" 
       id =<?php echo $row->title; ?> 
       value = "Unlocked" 
       onmouseover = "asktolock(this.id)" 
       onclick = "lockme(this.id)">
    </td> 
    <td><?php echo $row->assign_to; ?></td> 
    <td><a id="txt"></a></td> 
 </tr> 


Have your button populate a hidden formfield with a timestamp when it is clicked. Set the form to POST to a PHP script which processes the formfields and stores them where you like.

ETA: So on your form you'll need a field like this (with a unique name) for every timestamp you wish to store:

<input type='hidden' name='mytimestamp_unique' id='mytimestamp_unique' value=''/>

And then you'll add some code to your javascript function to set the value of the corresponding "mytimestamp" field. Something like:

function lockme(id){
 //parse the id to get the unique part of the id which is also the unique part of mytimestamp_unique
  var $hiddenfield=getElementById('mytimestamp_' + $uniquepart);
  $hiddenfield.value=new Date().getTime(); 

  //do other lockme stuff

}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号