Advertisement
brilliantmojo

SearchData.php

Jan 30th, 2020
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.89 KB | None | 0 0
  1. <?php
  2.  
  3.     if(isset($_POST['pageno']) || isset($_POST['ItemSearch'])){
  4.        
  5.         //Include database configuration file
  6.         include('../dbConfig.php');
  7.        
  8.         $limit = 10;
  9.         $pageno = $_POST['pageno'];
  10.         $offset = !empty($pageno) ? $pageno * $limit : 0;
  11.        
  12.         //set conditions for search
  13.         $whereSQL = $orderSQL = '';
  14.         $ItemSearch = $_POST['ItemSearch'];
  15.  
  16.         if(empty($ItemSearch)){
  17.                        
  18.             require('FilterData.php');
  19.        
  20.         } else {
  21.            
  22.             $whereSQL = "WHERE wt >= 2.5 AND number LIKE '%".$ItemSearch."%' ";
  23.             $orderSQL = "ORDER BY wt ASC";
  24.            
  25.         }
  26.        
  27.         //get number of rows
  28.         $queryNum = $db->query("SELECT COUNT(*) as number FROM stones ".$whereSQL.$orderSQL);
  29.         $resultNum = $queryNum->fetch_assoc();
  30.         $rowCount = $resultNum['number'];
  31.        
  32.         //initialize pagination class
  33.         $pagConfig = array(
  34.             'currentPage' => $offset,
  35.             'totalRows' => $rowCount,
  36.             'perPage' => $limit,
  37.             'link_func' => 'searchFilter'
  38.         );
  39.        
  40.         //get rows
  41.         $SQL = $db->query("
  42.             SELECT
  43.                 number,
  44.                 image1,
  45.                 wt,
  46.                 TRUNCATE(length,1) as length,
  47.                 TRUNCATE(width,1) as width,
  48.                 CASE
  49.                     WHEN stonetype = 'SA' THEN 'Sapphire'
  50.                     WHEN stonetype = 'RU' THEN 'Ruby'
  51.                     WHEN stonetype = 'TML-P' THEN 'Paraiba'
  52.                     WHEN stonetype = 'EM' THEN 'Emerald'
  53.                     WHEN stonetype = 'TS' THEN 'Tsavorite'
  54.                     WHEN stonetype = 'SI' THEN 'Spinel'
  55.                     WHEN stonetype = 'GT' THEN 'Garnet'
  56.                     WHEN stonetype = 'BER' THEN 'Beryl'
  57.                     WHEN stonetype = 'TML' THEN 'Tourmaline'
  58.                     WHEN stonetype = 'KO' THEN 'Kornerupine'
  59.                     ELSE 'n/a'
  60.                 END AS 'stonetype',
  61.                 CASE                                   
  62.                     WHEN enhcode = 'H' THEN 'Heated'
  63.                     WHEN enhcode = 'N' THEN 'Unheated'
  64.                     ELSE 'n/a'
  65.                 END AS 'enhcode'
  66.             FROM stones
  67.                 $whereSQL
  68.                 $orderSQL
  69.             LIMIT
  70.                 $offset,
  71.                 $limit
  72.         ");
  73.        
  74.         if($SQL->num_rows >= 1){
  75.            
  76.             while($row = $SQL->fetch_assoc()){
  77.            
  78.                 $postID = $row['number'];
  79.                
  80.                 echo '
  81.                     <div class="Stone">
  82.                    
  83.                         <!-- landing page -->
  84.                         <a href="#ItemPage" class="ItemLink" rel="modal:open" id="' . $row['number']. '">
  85.                    
  86.                             <!-- image -->
  87.                             <div class="StoneData StoneIMG"> <img src="../../' . $row['image1']. '"> </div>
  88.                            
  89.                             <!-- weight -->
  90.                             <div class="StoneData">' . $row['wt']. 'Ct</div>
  91.                            
  92.                             <!-- type -->
  93.                             <div class="StoneData">' . $row['stonetype']. '</div>
  94.                            
  95.                             <!-- enhancement -->
  96.                             <div class="StoneData">' . $row['enhcode']. '</div>
  97.                            
  98.                             <!-- dimensions -->
  99.                             <div class="StoneData">' . $row['length']. ' x ' . $row['width']. '</div>
  100.                            
  101.                             <!-- item number -->
  102.                             <div class="StoneData" id="Number"># ' . $row['number']. '</div>
  103.                        
  104.                         </a>
  105.                
  106.                     </div>
  107.                 ';
  108.                
  109.             }
  110.         } else {
  111.            
  112.             echo '
  113.                 <h1 class="Error">
  114.                     <span class="mdi mdi-magnify-close mdi-48px"></span>
  115.                     NO STONES MATCH THAT
  116.                 </h1>
  117.             ';
  118.         }
  119.        
  120.     }
  121.  
  122. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement