Advertisement
Guest User

Untitled

a guest
Nov 5th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.11 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <title>CubeMarket :: All Listings</title>
  5.     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
  6.     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
  7.     <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
  8.     <style>
  9.         h2, h4 {
  10.             text-align: center;
  11.         }
  12.     </style>
  13.     <?php
  14.     require ("navbar.php");
  15.     echo getNavBar("reports");
  16.     ?>
  17. </head>
  18. <body>
  19. <div class="jumbotron text-center">
  20.     <h1>All Cubes</h1>
  21.     <p>Viewing All Listings</p>
  22. </div>
  23. <div class="container">
  24.     <div id="recent-reports">
  25.  
  26.         <table class="table table-striped">
  27.  
  28.             <tr>
  29.                 <th>Name</th>
  30.                 <th>Description</th>
  31.                 <th>Category</th>
  32.                 <th>Condition</th>
  33.                 <th>Imgur Link</th>
  34.             </tr>
  35.  
  36.             <?php
  37.             global $servername, $username, $password, $dbname, $lastPageButton, $nextPageButton;
  38.  
  39.             $servername = "localhost";
  40.             $username = "root";
  41.             $password = "xxxxx";
  42.             $dbname = "cubemarket";
  43.             error_reporting(0);
  44.             $link = mysqli_connect($servername, $username, $password, $dbname, 3306) or die("Error on database connection.");
  45.            
  46.             $lastPageButton = TRUE;
  47.             $nextPageButton = TRUE;
  48.            
  49.             if (!isset($_GET['p'])) {
  50.                 $results = mysqli_query($link, "SELECT * FROM `listings` ORDER BY id DESC LIMIT 20;") or die("Error on database query.");
  51.             } else {
  52.                 $page = mysqli_real_escape_string($link, $_GET['p']);
  53.                 if ($page < 1) {
  54.                     $page = 1;
  55.                 }
  56.                 $first = (20 * ($page - 1)) + 1;
  57.                 $last = $first + 19;
  58.                 echo $first . " - " . $last;
  59.                 $results = mysqli_query($link, "SELECT * FROM `listings` WHERE id BETWEEN $first AND $last ORDER BY id DESC;") or die("Error on database query.");
  60.             }
  61.             if (mysqli_num_rows($results) > 0) {
  62.                 $tableResults = array();
  63.                 while ($row = mysqli_fetch_array($results)) {
  64.                     $id = $row['id'];
  65.                     $name = $row['name'];
  66.                     $description = $row['description'];
  67.                     $category = $row['category'];
  68.                     $condition = $row['cubecondition'];
  69.                     $imgurlink = $row['imgurlink'];
  70.                     $other = $row['otherinfo'];
  71.                     array_push($tableResults, array($name, $description, $category, $condition, $imgurlink));
  72.                 }
  73.                
  74.                 if (!isset($_GET['p'])) {
  75.                     $lastPageButton = FALSE;
  76.                 } elseif (mysqli_num_rows($allRows) == (20 + 20 * mysqli_real_escape_string($link, $_GET['p']))) {
  77.                     $nextPageButton = FALSE;
  78.                 }
  79.                
  80.                 $allRows = mysqli_query($link, "SELECT * FROM `listings`;") or die("Error on database query.");
  81.                
  82.                 foreach ($tableResults as $item) {
  83.                     echo "<tr><td><a href='http://xxx.xx.x.x/listing.php?id=$id'>$item[0]</a></td><td>$item[1]</td><td>$item[2]</td><td>$item[3]</td><td>$item[4]</td></tr>";
  84.                 }
  85.             } else {
  86.                 echo "<tr><td>No listings</td><td>No listings</td><td>No listings</td><td>No listings</td><td>No listings</td></tr>";
  87.             }
  88.             ?>
  89.  
  90.         </table>
  91.        
  92.         <?php
  93.             if ($lastPageButton) {
  94.                 echo "<form action='cube.php/?p={$_GET['p']-1}'><button type='submit'>Last page</button></form>";
  95.             }
  96.            
  97.             if ($nextPageButton) {
  98.                 echo "<form action='cube.php/?p={$_GET['p']+1}'><button type='submit'>Next page</button></form>";
  99.             }
  100.         ?>
  101.     </div>
  102. </div>
  103. </body>
  104. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement