Advertisement
Guest User

Leper's Colony - Year checker

a guest
Jan 29th, 2014
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.73 KB | None | 0 0
  1. <?php
  2. /*
  3.     filename: years.php
  4.     [there's a <form> tag with the action "years.php" (this file) so replace that if you use another filename]
  5.     don't host this on your website, it's not protected against SQL injection
  6.  */
  7. // this line is eventually used to convert month numbers into month names
  8. $month_array = array(
  9.         "1"  => "January",
  10.         "2"  => "February",
  11.         "3"  => "March",
  12.         "4"  => "April",
  13.         "5"  => "May",
  14.         "6"  => "June",
  15.         "7"  => "July",
  16.         "8"  => "August",
  17.         "9"  => "September",
  18.         "10" => "October",
  19.         "11" => "November",
  20.         "12" => "December",
  21. );
  22. if (!is_numeric($_GET['width']))
  23. {
  24.     $width = 500; // if you specify a non-numeric value for width, it defaults to 500
  25. }
  26. elseif($_GET['width'] == "")
  27. {
  28.     $width = 500; // same if you specify nothing at all
  29. }
  30. else
  31. {
  32.     $width = $_GET['width']; // this is when you specify width
  33. }
  34. // we're just gonna quickly gather the number of years this has been going on for.
  35.     $db = mysqli_connect("localhost","USERNAME","PASSWORD","sa") or die("The database has stopped working. :(");
  36.     $sql = "SELECT DISTINCT year FROM lc ORDER BY year ASC"; // this query eliminates all duplicate attention-seekers!
  37.     $result = mysqli_query($db,$sql);
  38.     $max = mysqli_num_rows($result);
  39.     mysqli_close($result);
  40. // everything will be explained later, don't worry
  41. ?>
  42. <html>
  43. <head>
  44. <title>Leper's Colony &bull; Year checker</title>
  45. <style type="text/css">
  46. body
  47. {
  48.     background-color: black;
  49.     color: white;
  50. }
  51. div
  52. {
  53.     height: 22px;
  54. }
  55. </style>
  56. </head>
  57. <body>
  58. <?php
  59. // now to create forms
  60. // there's a lot of C/P code so things won't be explained again
  61.     // Connect to MySQL database
  62.     $db = mysqli_connect("localhost","USERNAME","PASSWORD","sa") or die("The database has stopped working. :(");
  63.     $sql = "SELECT DISTINCT type FROM lc ORDER BY type ASC"; // this query eliminates all duplicate attention-seekers!
  64.     $result = mysqli_query($db,$sql);
  65. ?>
  66. <form action="years.php" method="get">
  67. <label>Type:
  68. <select name="type">
  69. <option value=''>None</option>
  70. <?php
  71. // this while loop creates an option for every request type (probation, ban, etc.) that exists
  72.     while($row = mysqli_fetch_assoc($result))
  73.     {
  74.         extract($row);
  75.         ?>
  76.             <option value='"<?php echo $row['type']; ?>"'><?php echo $row['type']; ?></option>
  77.         <?php
  78.     }
  79.     mysqli_close($result); // close the connection and then we can do the new one
  80. // the BANS + AUTOBANS option is hard-coded instead
  81. ?>
  82. <option value='1'>BANS + AUTOBANS</option>
  83. </select>
  84. </label>
  85. <?php
  86.     // Connect to MySQL database again
  87.     $db = mysqli_connect("localhost","USERNAME","PASSWORD","sa") or die("The database has stopped working. :(");
  88.     $sql = "SELECT DISTINCT requestor FROM lc ORDER BY requestor ASC"; // this query eliminates all duplicate attention-seekers!
  89.     $result = mysqli_query($db,$sql);
  90. ?>
  91. <label>Horrible mod:
  92. <select name="mod">
  93. <option value=''>None</option>
  94. <?php
  95. // now to create every option for every mod to grace the Leper's Colony ever
  96.     while($row = mysqli_fetch_assoc($result))
  97.     {
  98.         extract($row);
  99.         ?>
  100.             <option value='"<?php echo $row['requestor']; ?>"'><?php echo $row['requestor']; ?></option>
  101.         <?php
  102.     }
  103.     mysqli_close($result);
  104. ?>
  105. </select>
  106. </label>
  107. <?php
  108.     $db = mysqli_connect("localhost","USERNAME","PASSWORD","sa") or die("The database has stopped working. :(");
  109.     $sql = "SELECT DISTINCT day FROM lc ORDER BY day ASC"; // this query eliminates all duplicate attention-seekers!
  110.     $result = mysqli_query($db,$sql);
  111. ?>
  112. <label>Day:
  113. <select name="day">
  114. <option value=''>None</option>
  115. <?php
  116.     while($row = mysqli_fetch_assoc($result))
  117.     {
  118.         extract($row);
  119.         ?>
  120.             <option value='<?php echo $row['day']; ?>'><?php echo $row['day']; ?></option>
  121.         <?php
  122.     }
  123.     mysqli_close($result);
  124. ?>
  125. </select>
  126. </label>
  127. <?php
  128.     $db = mysqli_connect("localhost","USERNAME","PASSWORD","sa") or die("The database has stopped working. :(");
  129.     $sql = "SELECT DISTINCT month FROM lc ORDER BY month ASC"; // this query eliminates all duplicate attention-seekers!
  130.     $result = mysqli_query($db,$sql);
  131. ?>
  132. <label>Month:
  133. <select name="month">
  134. <option value=''>None</option>
  135. <?php
  136.     while($row = mysqli_fetch_assoc($result))
  137.     {
  138.         extract($row);
  139.         // what's happening here is month numbers become month names (ex. 7 => July)
  140.         $month2 = $row['month'];
  141.         $month  = $month_array[$month2];
  142.         ?>
  143.             <option value='<?php echo $row['month']; ?>'><?php echo $month; ?></option>
  144.         <?php
  145.     }
  146.     mysqli_close($result);
  147. ?>
  148. </select>
  149. </label>
  150. <label>Graph width:
  151. <input type="text" name="width" value="500" size="4" />
  152. </label>
  153. <input type="submit" value="Search!" />
  154. </form>
  155. <?php
  156.    
  157.     /*
  158.     End of form input fields. Now enter the actual data table!
  159.  
  160.     hey eveyone[sic], I'm a radium/chooch wannabe! :smug:
  161.      */
  162. ?>
  163. <table>
  164.     <tr>
  165.         <th>YEAR</th>
  166.         <th>NO. OF BANS</th>
  167.         <th>&nbsp;</th>
  168.     </tr>
  169. <?php
  170.     // Connect to MySQL database. so what
  171.     $db = mysqli_connect("localhost","USERNAME","PASSWORD","sa") or die("The database has stopped working. :(");
  172.     // a bunch of variables are being set up for upcoming loops
  173.     $i = 0;
  174.     $x = 0;
  175.     /*
  176.     the upcoming loop tries to find the highest result that will eventually be shown
  177.     this is to measure graph length
  178.  
  179.     oxma fat
  180.     RE: ozma fat
  181.      */
  182.     while($i < $max)
  183.     {
  184.         ++$i; // apparently this is faster than $i++. oh well
  185.         if($_GET['type'] == 1)
  186.         {
  187.             $sql = "SELECT * FROM lc WHERE year = ".$i." AND type NOT LIKE 'P%'"; // counts bans and autobans only
  188.         }
  189.         else
  190.         {
  191.             $sql = "SELECT * FROM lc WHERE year = ".$i; // sets up for upcoming AND queries
  192.             if ($_GET['type'] != "")
  193.             {
  194.                 $sql .= " AND type = ".$_GET['type']; // otherwise it's individual
  195.             }
  196.         }
  197.         if ($_GET['mod'] != "")
  198.         {
  199.             $sql .= " AND requestor = ".$_GET['mod'];
  200.         }
  201.         if ($_GET['day'] != "")
  202.         {
  203.             $sql .= " AND day = ".$_GET['day'];
  204.         }
  205.         if ($_GET['month'] != "")
  206.         {
  207.             $sql .= " AND month = ".$_GET['month'];
  208.         }
  209.         $result = mysqli_query($db,$sql);
  210.         // okay, now we should get the results
  211.         $num = mysqli_num_rows($result);
  212.         // if the result here is bigger than variable x, variable x is overwritten to define the new result
  213.         if ($num > $x)
  214.         {
  215.             $x = $num;
  216.         }
  217.         mysqli_close($result); // R.I.P. this stale comment. 888
  218.     }
  219.     $i = 0;
  220.     while($i < $max)
  221.     {
  222.         ?><tr><?php
  223.         ++$i;
  224.         if($_GET['type'] == 1)
  225.         {
  226.             $sql = "SELECT * FROM lc WHERE year = ".(3 + $i)." AND type NOT LIKE 'P%'"; // bans + autobans
  227.         }
  228.         else
  229.         {
  230.             $sql = "SELECT * FROM lc WHERE year = ".(3 + $i); // sets up for upcoming AND queries
  231.             if ($_GET['type'] != "")
  232.             {
  233.                 $sql .= " AND type = ".$_GET['type']; // otherwise individual type, mod, etc.
  234.             }
  235.         }
  236.         /*
  237.         variable i was 0, it should have risen by 1 now
  238.         3 + i should equal 4 at least
  239.         otherwise the first 3 years will always display 0 results
  240.         and the latest years will never show up
  241.          */
  242.         if ($_GET['mod'] != "")
  243.         {
  244.             $sql .= " AND requestor = ".$_GET['mod'];
  245.         }
  246.         if ($_GET['day'] != "")
  247.         {
  248.             $sql .= " AND day = ".$_GET['day'];
  249.         }
  250.         if ($_GET['month'] != "")
  251.         {
  252.             $sql .= " AND month = ".$_GET['month'];
  253.         }
  254.         $result = mysqli_query($db,$sql);
  255.         // okay, now we should get the results
  256.         $num = mysqli_num_rows($result);
  257.         /*
  258.         that huge line over there is the bar.
  259.         colour is determined by length, and  length / greatest result  (variable x) becomes a percent.
  260.         &nbsp; is a blank space; it's there to make the bar show up.
  261.  
  262.         echo 2003 + i, should equal 2004
  263.         otherwise it will show up as 1, 2, ... instead of 2004, 2005, ...
  264.          */
  265.         ?>
  266.         <td><?php echo 2003 + $i; ?></td>
  267.         <td><?php echo $num; ?></td>
  268.         <td style="width: 500px;"><div style="width: <?php echo ($num / $x)*100; ?>%; background-color: #<?php echo dechex(16777215 - $num); ?>">&nbsp;</div></td><?php echo "\n";
  269.         ?></tr><?php echo "\n";
  270.         mysqli_close($result);
  271.     }
  272. ?>
  273. </table>
  274. </body>
  275. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement