Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2013
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.55 KB | None | 0 0
  1.  
  2.  
  3.  
  4. <html>
  5. <head>
  6. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  7.                
  8. <link href="stylesheet.css" rel="stylesheet" type="text/css"/>
  9.  
  10. <title>Input</title>
  11. </head>
  12.  
  13. <body>
  14.     <div id="stylized" class="myform">
  15.  
  16.        
  17.            
  18.                 <h1>Search</h1>
  19.  
  20.                 <?php
  21.  
  22.                 require_once("ConnectionFactory.php");
  23.                 require_once("product_game.php");
  24.  
  25.                 ?>
  26.  
  27.                 <form method="POST" action="">
  28.                     <label>
  29.                         <span class="small">Name to search</span>
  30.                     </label>
  31.                     <input type="text" name="name"/>
  32.  
  33.                     <select name="select">
  34.                         <option value="Title">Title</option>
  35.                         <option value="Platform">Platform</option>
  36.                         <option value="Author">Author</option>
  37.                     </select>
  38.                     <input type="submit" input id="submitBtn">  
  39.                 </form>
  40.  
  41.                 <?php
  42.  
  43.                 try
  44.                 {
  45.                 $dbh = ConnectionFactory::connect();
  46.  
  47.  
  48.                 if(!isset($_POST['name']))
  49.                 {
  50.                     exit;
  51.                 }
  52.                 $search_term = $_POST['name'];
  53.  
  54.                 if(!isset($_POST['select']))
  55.                 {
  56.                     exit;
  57.                 }
  58.                 $search_topic = $_POST['select'];
  59.    
  60.                 switch($search_topic)
  61.                 {
  62.                     case 'Title':
  63.  
  64.                         $stmt = ConnectionFactory::select('platform_name','g.title');
  65.  
  66.                     break;
  67.  
  68.                     case 'Platform':
  69.  
  70.                         $stmt = ConnectionFactory::select('title','p.platform_name');
  71.  
  72.                     break;
  73.  
  74.                     case 'Author':
  75.  
  76.                         $stmt = ConnectionFactory::select('title','a.author_name');
  77.  
  78.                     break;
  79.                 }
  80.            
  81.  
  82.                 $stmt->bindValue(':search_term','%'.$search_term.'%');
  83.                
  84.                 $stmt->execute();
  85.                 $obj = $stmt->fetchALL(PDO::FETCH_CLASS, 'product_game');
  86.                
  87.                 $searchCount = sizeof($obj);
  88.  
  89.                 ?> <h4> <?php echo "Search for ". $search_term ." found " . $searchCount . " results" ?> </h4>
  90.  
  91.                 <form method="POST" action="">
  92.                     <select name="sorting">
  93.                         <option value="Title - A to Z"> Title - A to Z</option>
  94.                         <option value="Title - Z to A">Title - Z to A</option>
  95.                         <option value="Price - Low to High">Price - Low to High</option>
  96.                         <option value="Price - High to Low">Price - High to Low</option>
  97.                     </select>
  98.                     <input type="submit" value="submit" name="search_button" />
  99.                </form>
  100.  
  101.                 <?php
  102.  
  103.                 if(isset($_POST['search_button']))
  104.                 {
  105.                     print_r($_POST);
  106.                 }      
  107.                
  108.  
  109.                 if($searchCount != 0)
  110.                 {  
  111.  
  112.                 ?>           
  113.                   <ul class="products">        
  114.                       <?php
  115.                       foreach($obj as $product_game)
  116.                       {
  117.                           ?>
  118.                           <li>
  119.                               <a href="Details.php?productID=<?php echo $product_game->getID() ?>">
  120.                                   <img src="Thumbnails/<?php echo $product_game->getID()?>.png">
  121.                                   <h4><?php echo $product_game->getTitle() ?></h4>
  122.                                   <p>£<?php echo $product_game->getPrice() ?>.00</p>
  123.                               </a>
  124.                           </li>        
  125.                           <?php
  126.                       }
  127.                       ?>
  128.                   </ul>
  129.                   <?php
  130.                 }
  131.                 else
  132.                 {
  133.                     ?> <p> We could not find any products that matched your search. </p> <?php
  134.                 }
  135.                
  136.                 $dbh = null;
  137.             }
  138.             catch(PDOException $e)
  139.             {
  140.                 echo $e->getMessage();
  141.             }
  142.  
  143.  
  144.               ?>    
  145.                
  146.  
  147.     </div>
  148. </body>
  149. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement