Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <link href="stylesheet.css" rel="stylesheet" type="text/css"/>
- <title>Input</title>
- </head>
- <body>
- <div id="stylized" class="myform">
- <h1>Search</h1>
- <?php
- require_once("ConnectionFactory.php");
- require_once("product_game.php");
- ?>
- <form method="POST" action="">
- <label>
- <span class="small">Name to search</span>
- </label>
- <input type="text" name="name"/>
- <select name="select">
- <option value="Title">Title</option>
- <option value="Platform">Platform</option>
- <option value="Author">Author</option>
- </select>
- <input type="submit" input id="submitBtn">
- </form>
- <?php
- try
- {
- $dbh = ConnectionFactory::connect();
- if(!isset($_POST['name']))
- {
- exit;
- }
- $search_term = $_POST['name'];
- if(!isset($_POST['select']))
- {
- exit;
- }
- $search_topic = $_POST['select'];
- switch($search_topic)
- {
- case 'Title':
- $stmt = ConnectionFactory::select('platform_name','g.title');
- break;
- case 'Platform':
- $stmt = ConnectionFactory::select('title','p.platform_name');
- break;
- case 'Author':
- $stmt = ConnectionFactory::select('title','a.author_name');
- break;
- }
- $stmt->bindValue(':search_term','%'.$search_term.'%');
- $stmt->execute();
- $obj = $stmt->fetchALL(PDO::FETCH_CLASS, 'product_game');
- $searchCount = sizeof($obj);
- ?> <h4> <?php echo "Search for ". $search_term ." found " . $searchCount . " results" ?> </h4>
- <form method="POST" action="">
- <select name="sorting">
- <option value="Title - A to Z"> Title - A to Z</option>
- <option value="Title - Z to A">Title - Z to A</option>
- <option value="Price - Low to High">Price - Low to High</option>
- <option value="Price - High to Low">Price - High to Low</option>
- </select>
- <input type="submit" value="submit" name="search_button" />
- </form>
- <?php
- if(isset($_POST['search_button']))
- {
- print_r($_POST);
- }
- if($searchCount != 0)
- {
- ?>
- <ul class="products">
- <?php
- foreach($obj as $product_game)
- {
- ?>
- <li>
- <a href="Details.php?productID=<?php echo $product_game->getID() ?>">
- <img src="Thumbnails/<?php echo $product_game->getID()?>.png">
- <h4><?php echo $product_game->getTitle() ?></h4>
- <p>£<?php echo $product_game->getPrice() ?>.00</p>
- </a>
- </li>
- <?php
- }
- ?>
- </ul>
- <?php
- }
- else
- {
- ?> <p> We could not find any products that matched your search. </p> <?php
- }
- $dbh = null;
- }
- catch(PDOException $e)
- {
- echo $e->getMessage();
- }
- ?>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement