Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Inputted filters' values
- $ItemNumber = $_POST["ItemSearch"];
- $MinWT = $_POST["minimum_wt"];
- $MaxWT = $_POST["maximum_wt"];
- $Shape = $_POST["shape"];
- $Color = $_POST["color"];
- $Enhancement = $_POST["enhancement"];
- $Matching = $_POST["matching"];
- /* SELECT ALL (with the alias of 'inv' [to not mix up the following request])
- FROM the 'stones' table WHERE 'wt' is greater than or equal to 2.5,
- then COUNT ALL and use the window function; OVER() to partition the COUNT AS a column
- called 'totalrows' */
- $SQL = "
- SELECT inv.*, COUNT(*) OVER() AS totalrows FROM stones inv WHERE wt >= 2.5
- ";
- // Filters
- if(isset($ItemNumber)) {
- $SQL .= "
- AND number LIKE '".$ItemNumber."%'
- ";
- }
- if(isset($MinWT, $MaxWT) && !empty($MinWT) && !empty($MaxWT)) {
- $SQL .= "
- AND wt BETWEEN '".$MinWT."' AND '".$MaxWT."'
- ";
- }
- if(isset($Shape)) {
- $ShapeFilter = implode("','", $Shape);
- $SQL .= "
- AND stoneshape IN('".$ShapeFilter."')
- ";
- }
- if(isset($Color)) {
- $ColorFilter = implode("','", $Color);
- $SQL .= "
- AND stonecolor IN('".$ColorFilter."')
- ";
- }
- if(isset($Enhancement)) {
- $EnhancementFilter = implode("','", $Enhancement);
- $SQL .= "
- AND enhcode IN('".$EnhancementFilter."')
- ";
- }
- if(isset($Matching)) {
- $MatchingFilter = implode("','", $Matching);
- $SQL .= "
- AND pair IN('".$MatchingFilter."')
- ";
- }
- // Pagination
- $PageNo = $_REQUEST['PageNo']; // Get page number
- $Limit = 25; // Maximum iterations per page
- $Offset = ($PageNo - 1) * $Limit; // Current page times the amount per page
- // $Offset and $Limit are declared in their respective variables
- $SQL .= "
- ORDER BY wt ASC LIMIT $Offset, $Limit;
- ";
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement