Advertisement
Guest User

Untitled

a guest
Apr 19th, 2016
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.59 KB | None | 0 0
  1. <div id="page-wrap">
  2. <?php
  3. //if we got something through $_POST
  4. if (isset($_POST['search'])) {//load database connection
  5.     $host = "XXXXXX";
  6.     $user = "XXXXXX";
  7.     $password = "XXXXXX";
  8.     $database_name = "XXXXXX";
  9.     $pdo = new PDO("mysql:host=$host;dbname=$database_name", $user, $password, array(
  10.     PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
  11.     ));
  12. // Search from MySQL database table
  13. $search=$_POST['search'];
  14. $query = $pdo->prepare("SELECT itemname, itemprice, itemupdate FROM pricedata WHERE itemname LIKE '%" . $search . "%' ORDER BY itemprice DESC LIMIT 15");
  15. $query->bindValue(1, "%$search%", PDO::PARAM_STR);
  16. $query->execute();
  17. // Display search result
  18.          if (!$query->rowCount() == 0) {
  19.                 echo "<table class=\"table-fill\">";    
  20.                 echo "<thead>";
  21.                 echo "<tr>";
  22.                 echo "<th class=\"text-left\">Name and wear</th>";
  23.                 echo "<th class=\"text-left\">Price</th>";
  24.                 echo "<th class=\"text-left\">Update</th>";
  25.                 echo "</tr>";
  26.                 echo "</thead>";
  27.  
  28.             while ($results = $query->fetch()) {
  29.                 echo "<tbody class=\"table-hover\">";
  30.                 echo "<tr><td align=\"left\">";          
  31.                 echo $results['itemname'];
  32.                 echo "</td><td align=\"center\">";
  33.                 echo $results['itemprice'];
  34.                 echo "</td><td align=\"center\">";
  35.                 echo $results['itemupdate'];
  36.                 echo "</td></tr>";              
  37.             }
  38.                 echo "</tbody>";
  39.                 echo "</table>";        
  40.         } else {
  41.             echo 'Nothing found';
  42.         }
  43. }
  44. ?>
  45. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement