Advertisement
Guest User

Leper's Colony - Month checker

a guest
Jan 29th, 2014
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.10 KB | None | 0 0
  1. <?php
  2. /*
  3.     filename: months.php
  4.     [there's a <form> tag with the action "months.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 used to eventually 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. ?>
  35. <html>
  36. <head>
  37. <title>Leper's Colony &bull; Month checker</title>
  38. <style type="text/css">
  39. body
  40. {
  41.     background-color: black;
  42.     color: white;
  43. }
  44. div
  45. {
  46.     height: 22px;
  47. }
  48. </style>
  49. </head>
  50. <body>
  51. <?php
  52. // now to create forms
  53. // there's a lot of C/P code so things won't be explained again
  54.     // Connect to MySQL database
  55.     $db = mysqli_connect("localhost","USERNAME","PASSWORD","sa") or die("The database has stopped working. :(");
  56.     $sql = "SELECT DISTINCT type FROM lc ORDER BY type ASC"; // this query eliminates all duplicate attention-seekers!
  57.     $result = mysqli_query($db,$sql);
  58. ?>
  59. <form action="months.php" method="get">
  60. <label>Type:
  61. <select name="type">
  62. <option value=''>None</option>
  63. <?php
  64. // this while loop creates an option for every request type (probation, ban, etc.) that exists
  65.     while($row = mysqli_fetch_assoc($result))
  66.     {
  67.         extract($row);
  68.         ?>
  69.             <option value='"<?php echo $row['type']; ?>"'><?php echo $row['type']; ?></option>
  70.         <?php
  71.     }
  72.     mysqli_close($result); // close the connection and then we can do the new one
  73. // the BANS + AUTOBANS option is hard-coded instead
  74. ?>
  75. <option value='1'>BANS + AUTOBANS</option>
  76. </select>
  77. </label>
  78. <?php
  79.  
  80.     // Connect to MySQL database again
  81.     $db = mysqli_connect("localhost","USERNAME","PASSWORD","sa") or die("The database has stopped working. :(");
  82.     $sql = "SELECT DISTINCT requestor FROM lc ORDER BY requestor ASC"; // this query eliminates all duplicate attention-seekers!
  83.     $result = mysqli_query($db,$sql);
  84. ?>
  85. <label>Horrible mod:
  86. <select name="mod">
  87. <option value=''>None</option>
  88. <?php
  89. // now to create every option for every mod to grace the Leper's Colony ever
  90.     while($row = mysqli_fetch_assoc($result))
  91.     {
  92.         extract($row);
  93.         ?>
  94.             <option value='"<?php echo $row['requestor']; ?>"'><?php echo $row['requestor']; ?></option>
  95.         <?php
  96.     }
  97.     mysqli_close($result);
  98. ?>
  99. </select>
  100. </label>
  101. <?php
  102.     // Connect to MySQL database. so what
  103.     $db = mysqli_connect("localhost","USERNAME","PASSWORD","sa") or die("The database has stopped working. :(");
  104.     $sql = "SELECT DISTINCT day FROM lc ORDER BY day ASC"; // this query eliminates all duplicate attention-seekers!
  105.     $result = mysqli_query($db,$sql);
  106. ?>
  107. <label>Day:
  108. <select name="day">
  109. <option value=''>None</option>
  110. <?php
  111.     while($row = mysqli_fetch_assoc($result))
  112.     {
  113.         extract($row);
  114.         ?>
  115.             <option value='<?php echo $row['day']; ?>'><?php echo $row['day']; ?></option>
  116.         <?php
  117.     }
  118.     mysqli_close($result);
  119. ?>
  120. </select>
  121. </label>
  122. <?php
  123.     $db = mysqli_connect("localhost","USERNAME","PASSWORD","sa") or die("The database has stopped working. :(");
  124.     $sql = "SELECT DISTINCT year FROM lc ORDER BY year ASC"; // this query eliminates all duplicate attention-seekers!
  125.     $result = mysqli_query($db,$sql);
  126. ?>
  127. <label>Year:
  128. <select name="year">
  129. <option value=''>None</option>
  130. <?php
  131.     while($row = mysqli_fetch_assoc($result))
  132.     {
  133.         extract($row);
  134.         ?>
  135.             <option value='<?php echo $row['year']; ?>'><?php echo 2000 + $row['year']; ?></option>
  136.         <?php
  137.     }
  138.     mysqli_close($result);
  139.     /*
  140.     QUICK NOTE C/P: if you're wondering,
  141.     2000 + row['year'] will convert something like 7 to 2007,
  142.     simply putting 20 before the <?php echoing ?> the variable will interpret 7 as 207
  143.      */
  144. ?>
  145. </select>
  146. </label>
  147. <label>Graph width:
  148. <input type="text" name="width" value="500" size="4" />
  149. </label>
  150. <input type="submit" value="Search!" />
  151. </form>
  152. <?php
  153.    
  154.     /*
  155.     End of form input fields. Now enter the actual data table!
  156.  
  157.     insert dumb comment here, the php interpreter won't ignore it
  158.     it'll contact a mod of SA forums instead :o
  159.      */
  160. ?>
  161. <table>
  162.     <tr>
  163.         <th>MONTH</th>
  164.         <th>NO. OF BANS</th>
  165.         <th>&nbsp;</th>
  166.     </tr>
  167. <?php
  168.     // Connect to MySQL database. so what
  169.     $db = mysqli_connect("localhost","USERNAME","PASSWORD","sa") or die("The database has stopped working. :(");
  170.     // a bunch of variables are being set up for upcoming loops
  171.     $i = 0;
  172.     $x = 0;
  173.     /*
  174.     the upcoming loop tries to find the highest result that will eventually be shown
  175.     this is to measure graph length
  176.  
  177.     doob.gif
  178.      */
  179.     while($i < 12)
  180.     {
  181.         ++$i; // apparently this is faster than $i++. oh well
  182.         if($_GET['type'] == 1)
  183.         {
  184.             $sql = "SELECT * FROM lc WHERE month = ".$i." AND type NOT LIKE 'P%'"; // counts bans and autobans only
  185.         }
  186.         else
  187.         {
  188.             $sql = "SELECT * FROM lc WHERE month = ".$i; // sets up for upcoming AND queries
  189.             if ($_GET['type'] != "")
  190.             {
  191.                 $sql .= " AND type = ".$_GET['type']; // otherwise it's individual
  192.             }
  193.         }
  194.         if ($_GET['mod'] != "")
  195.         {
  196.             $sql .= " AND requestor = ".$_GET['mod'];
  197.         }
  198.         if ($_GET['day'] != "")
  199.         {
  200.             $sql .= " AND day = ".$_GET['day'];
  201.         }
  202.         if ($_GET['year'] != "")
  203.         {
  204.             $sql .= " AND year = ".$_GET['year'];
  205.         }
  206.         $result = mysqli_query($db,$sql);
  207.         // if the result here is bigger than variable x, variable x is overwritten to define the new result
  208.         $num = mysqli_num_rows($result);
  209.         if ($num > $x)
  210.         {
  211.             $x = $num;
  212.         }
  213.         mysqli_close($result); // I totally forgot what this does! honest!
  214.     }
  215.     $i = 0;
  216.     while($i < 12)
  217.     {
  218.         ?><tr><?php
  219.         ++$i;
  220.         if($_GET['type'] == 1)
  221.         {
  222.             $sql = "SELECT * FROM lc WHERE month = ".$i." AND type NOT LIKE 'P%'"; // bans + autobans
  223.         }
  224.         else
  225.         {
  226.             $sql = "SELECT * FROM lc WHERE month = ".$i; // sets up for upcoming AND queries
  227.             if ($_GET['type'] != "")
  228.             {
  229.                 $sql .= " AND type = ".$_GET['type']; // otherwise individual type, mod, etc.
  230.             }
  231.         }
  232.         if ($_GET['mod'] != "")
  233.         {
  234.             $sql .= " AND requestor = ".$_GET['mod'];
  235.         }
  236.         if ($_GET['day'] != "")
  237.         {
  238.             $sql .= " AND day = ".$_GET['day'];
  239.         }
  240.         if ($_GET['year'] != "")
  241.         {
  242.             $sql .= " AND year = ".$_GET['year'];
  243.         }
  244.         $result = mysqli_query($db,$sql);
  245.         // okay, now we should get the results
  246.         $num = mysqli_num_rows($result);
  247.         /*
  248.         that huge line over there is the bar.
  249.         colour is determined by length (number of results), and  length / greatest result  (variable x) becomes a percent.
  250.         &nbsp; is a blank space; it's there to make the bar show up.
  251.          */
  252.         ?>
  253.         <td><?php echo $month_array[$i]; ?></td>
  254.         <td><?php echo $num; ?></td>
  255.         <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";
  256.         ?></tr><?php echo "\n";
  257.         mysqli_close($result);
  258.     }
  259. ?>
  260. </table>
  261. </body>
  262. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement