开发者

How to create this script, into PHP function?

开发者 https://www.devze.com 2023-01-24 13:22 出处:网络
Here is a link, to the source: https://docs.google.com/document/pub?id=1VxiZbysGLVx71ni0biGm2NbhhSCkPZmGWng-ik7IHNQ

Here is a link, to the source: https://docs.google.com/document/pub?id=1VxiZbysGLVx71ni0biGm2NbhhSCkPZmGWng-ik7IHNQ

<?php  
$user1 = mysql_query("SELECT * FROM `users` WHERE `id`='$user-开发者_StackOverflow社区>id'");
while($user = mysql_fetch_object($user1)){
   $data2 = mysql_query("SELECT *,UNIX_TIMESTAMP(`start`) AS `start`,0 FROM `users` WHERE `id`='$user->id'");
   $data1 = mysql_fetch_object($data2);
   $date = $user->howlong;
   $timedif1 = $data1->start-3600+$date-time();
   if($data1->start + $date > time()){
       list($h,$min,$sec)=explode(":",date("H:i:s",$timedif1));
       $countdown = $data1->start+$date-time();
   }
}
?>

You have <?php echo $countdown ?> time to end!

Question: How to create this script, into PHP function?


It would be something like this:

<?php  

// getCountdown() function
function getCountdown($userId)
{
$user1 = mysql_query("SELECT * FROM `users` WHERE `id`='$userId'");
while($user = mysql_fetch_object($user1)){
   $data2 = mysql_query("SELECT *,UNIX_TIMESTAMP(`start`) AS `start`,0 FROM `users` WHERE `id`='$userId'");
   $data1 = mysql_fetch_object($data2);
   $date = $user->howlong;
   $timedif1 = $data1->start-3600+$date-time();
   if($data1->start + $date > time()){
       list($h,$min,$sec)=explode(":",date("H:i:s",$timedif1));
       $countdown = $data1->start+$date-time();
   }
 return $countdown;
}

// call function and pass user id parameter
$countdown = getCountdown($user->id);
// display function output
echo $countdown;

?>


function yourfuction(){
  $user1 = mysql_query("SELECT * FROM `users` WHERE `id`='$user->id'");
  while($user = mysql_fetch_object($user1)){
  $data2 = mysql_query("SELECT *,UNIX_TIMESTAMP(`start`) AS `start`,0 FROM `users` where
  `id`='$user->id'");
  $data1 = mysql_fetch_object($data2);
  $date = $user->howlong;
  $timedif1 = $data1->start-3600+$date-time();
  if($data1->start + $date > time()){
   list($h,$min,$sec)=explode(":",date("H:i:s",$timedif1));
  $countdown = $data1->start+$date-time();
}
0

精彩评论

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