Advertisement
dumle29

Average life expectantcy V0.2.0

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