Advertisement
dumle29

Average life expectantcy V0.1.2

Nov 13th, 2012
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.68 KB | None | 0 0
  1. <?php
  2. /*
  3. V0.1.2
  4. !!DOES NOT WORK!!
  5. !!SEE VERSION 0.2.0!!
  6. !!http://pastebin.com/QwPeb6u3!!
  7. Made by Mikkel Jeppsen, a.k.a. smuttenDK a.k.a. dumle29.
  8.  
  9. Script to get the average survival time of the players on your bliss based dayz privatehived server,
  10. and show it on your site.
  11.  
  12.  
  13. To use this:
  14. Option 1:
  15.     Put this code in a file and name it NAME.php
  16.     Then, the place you want it on your site, enter <?php include 'PATH/TO/FILE/NAME.php' ?>
  17.  
  18. Option 2:
  19.     Paste this code in to your site, the place you want it to appear.
  20. */
  21.  
  22. /*---------------Start of config---------------*/
  23.     $host = "HOSTNAME"; //Put the hostname or the ip of your database server here.
  24.         $user = "USERNAME"; //Put your username here.
  25.         $pass = "PASSWORD"; //Enter your password to the database here.
  26.         $dataBase = "DBNAME"; //Enter the name of your database here.
  27.    
  28.     $minLim = 10;   //Minimum amount of minutes to have lived before it is included in the average
  29.    
  30.     $hourSingular = "hour";    //Allows you to change the word used for the singularium of hour.
  31.     $hourPlural = "hours";    //Allows you to change the word used for the plural of hour.
  32.    
  33.     $andStr = "and";    //Allows you to change the word used to combine the hours and minutes string.
  34.    
  35.     $minuteSingular = "minute";    //Allows you to change the word used for the singularium of minute.
  36.     $minutePlural = "minutes";    //Allows you to change the word used for the plural of minute.
  37.  
  38. /*---------------End of config---------------*/
  39.  
  40.     $minutes = 0;
  41.     $hours = 0;
  42.     $average = 0;
  43.  
  44.     $con = mysql_connect($host,$user,$pass);
  45.     if (!$con)
  46.     {
  47.         die('Could not connect: ' . mysql_error());
  48.     }
  49.    
  50.     mysql_select_db($dataBase, $con) or die(mysql_error());
  51.    
  52.     $sql = "SELECT AVG(total_survival_time) FROM profile WHERE total_survival_time >=". $minLim;
  53.    
  54.     $resultRaw = mysql_query($sql);
  55.        
  56.     if(!$averageArr = mysql_fetch_row($resultRaw))
  57.     {
  58.         $minutes = 0;
  59.     }
  60.     else
  61.     {  
  62.         $minutes = round($averageArr[0],0);
  63.     }
  64.     if($minutes > 59)
  65.     {
  66.         $hours = floor($minutes / 60);
  67.         $minutes = $minutes % 60;
  68.     }
  69.    
  70.     if($hours > 1)
  71.     {
  72.         $hourStr = $hours . ' ' . $hourPlural;
  73.     }
  74.     else if($hours <= 1 && $hours > 0)
  75.     {
  76.         $hourStr = $hours. ' ' . $hourSingular;
  77.     }
  78.     else
  79.     {
  80.         $hourStr = ''; 
  81.     }
  82.    
  83.     if($minutes > 1)
  84.     {
  85.         $minuteStr =$minutes. ' ' . $minutePlural;
  86.     }
  87.     else if($minutes <= 1 && $minutes > 0)
  88.     {
  89.         $minuteStr =$minutes. ' ' . $minuteSingular;
  90.     }
  91.     else if($minutes == 0 && !$hours)
  92.     {
  93.         $minuteStr =$minutes. ' ' . $minutePlural;
  94.     }
  95.     else
  96.     {
  97.         $minuteStr = '';   
  98.     }
  99.  
  100.     if($hourStr != '' && $minutes != '')
  101.     {
  102.         $andStr =' '. $andStr .' ';
  103.     }
  104.     else
  105.     {
  106.         $andStr = '';  
  107.     }
  108.    
  109.     echo $hourStr . $andStr . $minuteStr;
  110. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement