brilliantmojo

SQLDataMangement.php

Apr 14th, 2020 (edited)
466
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.00 KB | None | 0 0
  1. <?php
  2.  
  3.     /*
  4.         Select all as the alias 'inv' from the 'stones' table
  5.         Count all rows and store the number for rows in the variable 'totalRows'
  6.         as long as the 'wt' column is greater than or equal to 2.5
  7.     */
  8.  
  9.     $SQL = "SELECT inv.*, COUNT(*) OVER() AS totalrows FROM stones inv WHERE wt >= 2.5";
  10.    
  11.    
  12.     if (isset($_POST["ItemSearch"])) $SQL .= "AND number LIKE '" . $_POST["ItemSearch"] . "%'";
  13.  
  14.     if (isset($_POST["minimum_wt"], $_POST["maximum_wt"]) && !empty($_POST["minimum_wt"]) && !empty($_POST["maximum_wt"])) $SQL .= "AND wt BETWEEN '" . $_POST["minimum_wt"] . "' AND '" . $_POST["maximum_wt"] . "'";
  15.    
  16.     if (isset($_POST["shape"])) {
  17.  
  18.         $ShapeFilter_SharpCorners = ["EC", "AS", "RA", "PR"]; // Emerald cut, Asscher, Radiant, Princess cut
  19.        
  20.         $ShapeFilter = implode("','", $_POST["shape"]);
  21.        
  22.         $SQL .= "AND stoneshape IN('" . $ShapeFilter . "')";
  23.        
  24.     }
  25.    
  26.     if (isset($_POST["color"])) {
  27.        
  28.         $ColorFilter = implode("','", $_POST["color"]);
  29.        
  30.         $SQL .= "AND stonecolor IN('" . $ColorFilter . "')";
  31.                
  32.     }
  33.    
  34.     if (isset($_POST["enhancement"])) {
  35.        
  36.         $EnhancementFilter = implode("','", $_POST["enhancement"]);
  37.        
  38.         $SQL .= "AND enhcode IN('" . $EnhancementFilter . "')";
  39.                    
  40.     }
  41.    
  42.     if (isset($_POST["matching"])) {
  43.        
  44.         $MatchingFilter = implode("','", $_POST["matching"]);
  45.        
  46.         $SQL .= "AND pair IN('" . $MatchingFilter . "')";  
  47.                    
  48.     }
  49.    
  50.     $PageNo = $_REQUEST['PageNo']; // Get page number (paginate)
  51.  
  52.     $Limit = 25; // Items per page
  53.  
  54.     $Offset = ($PageNo - 1) * $Limit; // Current page times the amount per page
  55.    
  56.     $SQL .= "AND inactive LIKE 0 ORDER BY wt ASC LIMIT $Offset, $Limit;"; // $Offset and $Limit are declared in their respective variables
  57.  
  58.     $MySQLiQuery = mysqli_query($db, $SQL); // Preform the query against the database
  59.  
  60. ?>
Add Comment
Please, Sign In to add comment