Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php header('Content-Type: text/html; charset=utf-8');?>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- </head>
- <body>
- <?php
- $MYSQLSERVER = "localhost";
- $USER = "root";
- $PASSWORD = "";
- $DATABASE = "registro";
- $location = file_get_contents('http://api.geoiplookup.net/?query='.$_SERVER['REMOTE_ADDR']);
- $location = new SimpleXMLElement($location);
- $location = utf8_decode($location->results->result->countryname.", ".$location->results->result->city);
- $mysqli = new mysqli($MYSQLSERVER, $USER, $PASSWORD, $DATABASE);
- $mysqli->set_charset("utf8");
- date_default_timezone_set ("Europe/Madrid");
- if ($mysqli->connect_errno) {
- echo "ERROR DB";
- die('Error de conexión: ' . $mysqli->connect_error);
- exit;
- }
- if(isset($_REQUEST["player_name"])){
- $player_name = trim(urldecode($_REQUEST["player_name"]));
- $stmt = $mysqli->prepare("INSERT INTO registro (player_name, player_id, type, info, location, equipo) VALUES (?,?,?,?,?,?)");
- $stmt->bind_param('ssssss',$player_name,$_REQUEST["player_id"],$_REQUEST["type"],$_REQUEST["info"],$location,$_REQUEST["equipo"]);
- if (!$stmt->execute()) {
- echo "ERROR SQL";
- exit;
- }
- $stmt->close();
- }else{
- $p = 0;
- $items_per_page = 100;
- if(isset($_REQUEST["p"])){
- $p = $_REQUEST["p"];
- }
- $offset = $p*$items_per_page;
- if(isset($_REQUEST["filter_type"])){
- $stmt = $mysqli->prepare("SELECT id, player_id, player_name, type, date, info, location, equipo FROM registro WHERE type = ? LIMIT ?,?");
- $stmt->bind_param('sdd', $_REQUEST["filter_type"], $offset, $items_per_page);
- $stmt_total = $mysqli->prepare("SELECT count(player_id) as total FROM registro WHERE type = ?");
- $stmt_total->bind_param('s', $_REQUEST["filter_type"]);
- $stmt_total->execute();
- $result_total = $stmt_total->get_result();
- $row_total = $result_total->fetch_assoc();
- $total_items = $row_total["total"];
- }else if(isset($_REQUEST["filter_id"])){
- $stmt = $mysqli->prepare("SELECT id, player_id, player_name, type, date, info, location, equipo FROM registro WHERE player_id = ? LIMIT ?,?");
- $stmt->bind_param('sdd', $_REQUEST["filter_id"], $offset, $items_per_page);
- $stmt_total = $mysqli->prepare("SELECT count(player_id) as total FROM registro WHERE player_id = ?");
- $stmt_total->bind_param('s', $_REQUEST["filter_id"]);
- $stmt_total->execute();
- $result_total = $stmt_total->get_result();
- $row_total = $result_total->fetch_assoc();
- $total_items = $row_total["total"];
- }else{
- $stmt = $mysqli->prepare("SELECT id, player_id, player_name, type, date, info, location, equipo FROM registro ORDER BY date DESC LIMIT ?,?");
- $stmt->bind_param('dd', $offset, $items_per_page);
- $stmt_total = $mysqli->prepare("SELECT count(player_id) as total FROM registro");
- $stmt_total->execute();
- $result_total = $stmt_total->get_result();
- $row_total = $result_total->fetch_assoc();
- $total_items = $row_total["total"];
- }
- if (!$stmt->execute()) {
- echo "ERROR SQL";
- exit;
- }
- $last_page = floor($total_items/$items_per_page);
- $result = $stmt->get_result();
- ?>
- <a href="/registro.php"><h2>Inicio</h2></a>
- Total de entradas <?php echo $total_items; ?>
- <table border=1>
- <thead>
- <tr>
- <th>Player ID</th>
- <th>Player Name</th>
- <th>Tipo</th>
- <th>Fecha</th>
- <th>Info</th>
- <th>Ubicación</th>
- <th>Equipo</th>
- </tr>
- </thead>
- <tbody>
- <?php
- while($row = $result->fetch_assoc()){
- $dt = new DateTime($row["date"]);
- $dt->setTimezone(new DateTimeZone('Europe/Madrid'));
- ?>
- <tr>
- <td><a href="registro.php?filter_id=<?php echo $row["player_id"];?>"><?php echo $row["player_id"];?></a></td>
- <td><?php echo $row["player_name"];?></td>
- <td><a href="registro.php?filter_type=<?php echo $row["type"];?>"><?php echo $row["type"];?></a></td>
- <td><?php echo $dt->format('Y-m-d H:i:s');?></td>
- <td><?php echo $row["info"];?></td>
- <td><?php echo $row["location"];?></td>
- <td><?php echo $row["equipo"];?></td>
- </tr>
- <?php
- }
- ?>
- </tbody>
- </table>
- <br>
- <?php if(isset($_REQUEST["filter_type"])){ ?>
- <a href="registro.php?p=0&filter_type=<?php echo $_REQUEST["filter_type"]; ?>"><<</a>
- <?php
- if($p != 0){
- ?>
- <a href="registro.php?p=<?php echo $p-1; ?>&filter_type=<?php echo $_REQUEST["filter_type"]; ?>"><-Antrás</a>
- <?php
- }
- ?>
- <?php
- if($p < $last_page){
- ?>
- <a href="registro.php?p=<?php echo $p+1; ?>&filter_type=<?php echo $_REQUEST["filter_type"]; ?>">Siguiente-></a>
- <?php
- }
- ?>
- <a href="registro.php?p=<?php echo $last_page; ?>&filter_type=<?php echo $_REQUEST["filter_type"]; ?>">>></a>
- <?php } elseif(isset($_REQUEST["filter_id"])){ ?>
- <a href="registro.php?p=0&filter_id=<?php echo $_REQUEST["filter_id"]; ?>"><<</a>
- <?php
- if($p != 0){
- ?>
- <a href="registro.php?p=<?php echo $p-1; ?>&filter_id=<?php echo $_REQUEST["filter_id"]; ?>"><-Antrás</a>
- <?php
- }
- ?>
- <?php
- if($p < $last_page){
- ?>
- <a href="registro.php?p=<?php echo $p+1; ?>&filter_id=<?php echo $_REQUEST["filter_id"]; ?>">Siguiente-></a>
- <?php
- }
- ?>
- <a href="registro.php?p=<?php echo $last_page; ?>&filter_id=<?php echo $_REQUEST["filter_id"]; ?>">>></a>
- <?php }else{ ?>
- <a href="registro.php?p=0"><<</a>
- <?php
- if($p != 0){
- ?>
- <a href="registro.php?p=<?php echo $p-1; ?>"><-Antrás</a>
- <?php
- }
- ?>
- <?php
- if($p < $last_page){
- ?>
- <a href="registro.php?p=<?php echo $p+1; ?>">Siguiente-></a>
- <?php
- }
- ?>
- <a href="registro.php?p=<?php echo $last_page; ?>">>></a>
- <?php } ?>
- <br><br><br><br>
- <?php
- $stmt->close();
- }
- $mysqli->close();
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement