Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- filename: mods.php
- [there's a <form> tag with the action "mods.php" (this file) so replace that if you use another filename]
- don't host this on a website, it's not protected against SQL injection etc.
- */
- // this line is eventually used to convert month numbers into month names
- $month_array = array(
- "1" => "January",
- "2" => "February",
- "3" => "March",
- "4" => "April",
- "5" => "May",
- "6" => "June",
- "7" => "July",
- "8" => "August",
- "9" => "September",
- "10" => "October",
- "11" => "November",
- "12" => "December",
- );
- if (!is_numeric($_GET['width']))
- {
- $width = 500; // if the URL variable "width" is not a number, the width is 500 px
- }
- elseif($_GET['width'] == "")
- {
- $width = 500; // if it's not defined, it defaults to 500 px
- }
- else
- {
- $width = $_GET['width']; // this is when you input a proper number
- }
- ?>
- <html>
- <head>
- <title>Leper's Colony • Nuke all mods edition</title>
- <style type="text/css">
- body
- {
- background-color: black;
- color: white;
- }
- div
- {
- height: 22px;
- }
- </style>
- </head>
- <body>
- <?php
- // Connect to MySQL database
- $db = mysqli_connect("localhost","USERNAME","PASSWORD","sa") or die("The database has stopped working. :(");
- $sql = "SELECT DISTINCT type FROM lc ORDER BY type ASC"; // this query eliminates all duplicates
- $result = mysqli_query($db,$sql);
- ?>
- <form action="mods.php" method="get">
- <label>Type:
- <select name="type">
- <option value=''>None</option>
- <?php
- // this will create an option for every unique type (ban, probation, etc.) that exists
- while($row = mysqli_fetch_assoc($result))
- {
- extract($row);
- ?>
- <option value='"<?php echo $row['type']; ?>"'><?php echo $row['type']; ?></option>
- <?php
- }
- mysqli_close($result); // close this
- ?>
- <option value='1'>BANS + AUTOBANS</option>
- </select>
- </label>
- <?php
- $db = mysqli_connect("localhost","USERNAME","PASSWORD","sa") or die("The database has stopped working. :(");
- $sql = "SELECT DISTINCT day FROM lc ORDER BY day ASC";
- $result = mysqli_query($db,$sql);
- ?>
- <label>Day:
- <select name="day">
- <option value=''>None</option>
- <?php
- while($row = mysqli_fetch_assoc($result))
- {
- extract($row);
- ?>
- <option value='<?php echo $row['day']; ?>'><?php echo $row['day']; ?></option>
- <?php
- }
- mysqli_close($result);
- ?>
- </select>
- </label>
- <?php
- $db = mysqli_connect("localhost","USERNAME","PASSWORD","sa") or die("The database has stopped working. :(");
- $sql = "SELECT DISTINCT month FROM lc ORDER BY month ASC"; // this query eliminates all duplicate attention-seekers!
- $result = mysqli_query($db,$sql);
- ?>
- <label>Month:
- <select name="month">
- <option value=''>None</option>
- <?php
- while($row = mysqli_fetch_assoc($result))
- {
- extract($row);
- // convert month numbers into month names
- $month2 = $row['month'];
- $month = $month_array[$month2];
- ?>
- <option value='<?php echo $row['month']; ?>'><?php echo $month; ?></option>
- <?php
- }
- mysqli_close($result);
- ?>
- </select>
- </label>
- <?php
- $db = mysqli_connect("localhost","USERNAME","PASSWORD","sa") or die("The database has stopped working. :(");
- $sql = "SELECT DISTINCT year FROM lc ORDER BY year ASC"; // this query eliminates all duplicate attention-seekers!
- $result = mysqli_query($db,$sql);
- ?>
- <label>Year:
- <select name="year">
- <option value=''>None</option>
- <?php
- while($row = mysqli_fetch_assoc($result))
- {
- extract($row);
- ?>
- <option value='<?php echo $row['year']; ?>'><?php echo 2000 + $row['year']; ?></option>
- <?php
- }
- mysqli_close($result);
- ?>
- </select>
- </label>
- <label>Graph width:
- <input type="text" name="width" value="500" size="4" />
- </label>
- <br />
- <label>Look for mods with over:
- <input type="text" name="num_requests" value="1000" size="4" />
- requests</label>
- <input type="submit" value="Search!" />
- </form>
- <?php
- /*
- End of form input fields. Now enter the actual data table!
- the following query will find some values needed for upcoming queries
- */
- $db = mysqli_connect("localhost","USERNAME","PASSWORD","sa") or die("The database has stopped working. :(");
- $sql = "SELECT DISTINCT requestor FROM lc ORDER BY requestor ASC";
- $result = mysqli_query($db,$sql);
- // variable max stores number of mods
- $max = mysqli_num_rows($result);
- /*
- array mod_array stores each row into an array
- mysqli_fetch_all is only available starting PHP 5.3.0 so keep that in mind,
- no, mysqli_fetch_array does not do the job: it only picks up the first row
- */
- $mod_array = mysqli_fetch_all($result,MYSQLI_NUM);
- mysqli_close($result);
- ?>
- <table>
- <tr>
- <th>MOD</th>
- <th>NO. OF REQUESTS MADE</th>
- <th> </th>
- </tr>
- <?php
- $db = mysqli_connect("localhost","USERNAME","PASSWORD","sa") or die("The database has stopped working. :(");
- $i = 0; // increment value for while loop
- $x = 0; // eventually stores highest result
- while($i < $max)
- {
- if($_GET['type'] == 1)
- {
- $sql = "SELECT * FROM lc WHERE requestor = '".$mod_array[$i][0]."' AND type NOT LIKE 'P%'"; // Bans + autobans
- }
- else
- {
- $sql = "SELECT * FROM lc WHERE requestor = '".$mod_array[$i][0]."'"; // sets up for upcoming AND queries
- if ($_GET['type'] != "")
- {
- $sql .= " AND type = ".$_GET['type']; // individual type of request
- }
- }
- if ($_GET['day'] != "")
- {
- $sql .= " AND day = ".$_GET['day']; // day, month, etc.
- }
- if ($_GET['month'] != "")
- {
- $sql .= " AND month = ".$_GET['month'];
- }
- if ($_GET['year'] != "")
- {
- $sql .= " AND year = ".$_GET['year'];
- }
- $result = mysqli_query($db,$sql);
- // we're gonna set the highest limit for the graph.
- $num = mysqli_num_rows($result);
- if ($num > $x)
- {
- $x = $num;
- }
- ++$i; // we do this at the end because array starts at 0
- mysqli_close($result);
- }
- $i = 0;
- while($i < $max)
- {
- ?><tr><?php
- if($_GET['type'] == 1)
- {
- $sql = "SELECT * FROM lc WHERE requestor = '".$mod_array[$i][0]."' AND type NOT LIKE 'P%'";
- }
- else
- {
- $sql = "SELECT * FROM lc WHERE requestor = '".$mod_array[$i][0]."'"; // sets up for upcoming AND queries
- if ($_GET['type'] != "")
- {
- $sql .= " AND type = ".$_GET['type'];
- }
- }
- if ($_GET['day'] != "")
- {
- $sql .= " AND day = ".$_GET['day'];
- }
- if ($_GET['month'] != "")
- {
- $sql .= " AND month = ".$_GET['month'];
- }
- if ($_GET['year'] != "")
- {
- $sql .= " AND year = ".$_GET['year'];
- }
- $result = mysqli_query($db,$sql);
- // okay, now we should get the results
- $num = mysqli_num_rows($result);
- // are we looking for mods who deliver over y results?
- if ($_GET['num_requests'] != "")
- {
- if ($num < $_GET['num_requests'])
- {
- ++$i; // if it doesn't match, just go on to the next row
- }
- else
- {
- ?>
- <td><?php echo $mod_array[$i][0]; ?></td>
- <td><?php echo $num; ?></td>
- <td style="width: <?php echo $width; ?>px;"><div style="width: <?php echo ($num / $x)*100; ?>%; background-color: #<?php echo dechex(16777215 - $num); ?>"> </div></td><?php echo "\n";
- ?></tr><?php echo "\n";
- ++$i; // ok, it matches, do all that stuff
- mysqli_close($result);
- }
- }
- else
- // no, we're not
- {
- ?>
- <td><?php echo $mod_array[$i][0]; ?></td>
- <td><?php echo $num; ?></td>
- <td style="width: <?php echo $width; ?>px;"><div style="width: <?php echo ($num / $x)*100; ?>%; background-color: #<?php echo dechex(16777215 - $num); ?>"> </div></td><?php echo "\n";
- ?></tr><?php echo "\n";
- ++$i; //
- mysqli_close($result);
- }
- }
- ?>
- </table>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement