Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if(isset($_GET['search'])) {
- try {
- $dsn = 'mysql:host=localhost;dbname=bajan_glasses';
- $db = new PDO($dsn, 'glasses_cms', '8019');
- $sql = 'SELECT id, category, style, color, material, size, price, image,
- position, caption, visible
- FROM eyeglasses
- WHERE id LIKE id AND category = category AND style = style AND
- color = color
- AND material = material AND size = size AND price = price AND
- image = image AND position = position
- AND caption = caption AND visible = visible
- ORDER BY id';
- // <!--------------------- when ":" is added to the above , the table
- does not display------------->
- $stmt = $db->prepare($sql);
- $stmt->bindValue(':id', '%' . $_GET['id'] . '%');
- // $stmt->bindParam(':id', $_GET['id'], PDO::PARAM_INT);
- $stmt->bindParam(':category', $_GET['category'], PDO::PARAM_STR);
- $stmt->bindParam(':style', $_GET['style'], PDO::PARAM_STR);
- $stmt->bindParam(':color', $_GET['color'], PDO::PARAM_STR);
- $stmt->bindParam(':material', $_GET['material'], PDO::PARAM_STR);
- $stmt->bindParam(':size', $_GET['size'], PDO::PARAM_INT);
- $stmt->bindParam(':price', $_GET['price'], PDO::PARAM_INT);
- $stmt->bindParam(':image', $_GET['image'], PDO::PARAM_INT);
- $stmt->bindParam(':position', $_GET['position'], PDO::PARAM_INT);
- $stmt->bindParam(':caption', $_GET['caption'], PDO::PARAM_STR);
- $stmt->bindParam(':visible', $_GET['visible'], PDO::PARAM_INT);
- // $stmt->execute('bindParam'); // use://if still getting token error.
- $stmt->execute();
- if (isset($errorInfo[2])) {
- $error = $errorInfo[2];
- }
- } catch (Exception $e) {
- $error = $e->getMessage();
- }
- }
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <title>PDO: SELECT Loop</title>
- <link href="../../styles/styles.css" rel="stylesheet" type="text/css">
- </head>
- <body>
- <form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">
- <fieldset>
- <p>
- <label for="id">id </label>
- <select name="id" id="id">
- <?php
- //$material = array('woo' => 'wood');
- //$material = array('ace' => 'acetate');
- ///$material = array('pla' => 'plastic');
- //$material = array('ste' => 'steel');
- for ($id =0; $id <=1 ; $id++) {
- echo "<option>$id</option>";
- };
- ?>
- </select>
- <label for="category ">category </label>
- <select name="category " id="category ">
- <option> </option>
- <option>men</option>
- <option>women</option>
- <option>children</option>
- </select>
- <label for="style ">style </label>
- <select name="style " id="style ">
- <option selected value="style">style</option>
- <option>aviator</option>
- <option>rectangular</option>
- <option>round</option>
- <option>square</option>
- <option>vintage</option>
- <option>black</option>
- </select>
- <label for="color ">color </label>
- <select name="color " id="color ">
- <option></option>
- <option>white</option>
- <option>blue</option>
- <option>green</option>
- <option>yellow</option>
- <option>brown</option>
- <option>black</option>
- <option>red</option>
- <option>pink</option>
- <option>pink</option>
- </select>
- <label for="material">Material </label>
- <select name="material" id="material">
- <?php
- //$material = array('woo' => 'wood');
- //$material = array('ace' => 'acetate');
- ///$material = array('pla' => 'plastic');
- //$material = array('ste' => 'steel');
- // for ($material = 'wood'+'steel'; $material <= 'plastic'; $material++)
- {
- // echo "<option>$material</option>";
- // };
- ?>
- <option> </option>
- <option>wood</option>
- <option>acetate</option>
- <option>plastic </option>
- <option>steel </option>
- </select>
- <label for="size">size </label>
- <select name="size" id="size">
- <?php
- $size = array('sma' => 'small');
- $size = array('med' => 'medium');
- $size = array('lar' => 'large');
- for ($size= 'small'; $size<= 'medium'; $size++) {
- echo "<option>$size</option>";
- };
- ?>
- <option> </option>
- <option>small</option>
- <option>medium</option>
- <option>large</option>
- </select>
- <label for="price ">price</label>
- <select name="price " id="price ">
- <option selected value="price"></option>
- <option>$199</option>
- <option>rectangular</option>
- <option>$259</option>
- <option>$129</option>
- <option>$111</option>
- <option>$111</option>
- </select>
- <label for="style ">image </label>
- <select name="image " id="image ">
- <option ></option>
- </select>
- <label for="style ">position</label>
- <select name="style " id="style ">
- <option selected value="position"></option>
- <option>1</option>
- <option>2</option>
- <option>3</option>
- </select>
- <label for="style ">caption</label>
- <select name="style " id="style ">
- <option selected value="style"></option>
- <option>Choose from Mens styles...</option>
- <option>men glasses</option>
- <option>women glasses</option>
- <option> children glasses...</option>
- </select>
- <label for="visible ">visible </label>
- <select name="visible " id="visible ">
- <option></option>
- <option>1</option>
- <option>2</option>
- <option>3</option>
- </select>
- <input type="submit" name="search" value="Search">
- </p>
- </fieldset>
- </form>
- <?php if (isset($_GET['search'])) {
- $row = $stmt->fetch();
- if ($row) {
- ?>
- <table>
- <tr>
- <th>id</th>
- <th>category</th>
- <th>style</th>
- <th>color</th>
- <th>material</th>
- <th>size</th>
- <th>price</th>
- <th>image</th>
- <th>position</th>
- <th>caption</th>
- <th>visible</th>
- </tr>
- <?php /******** foreach ($db->query($sql) as $row) {*********/?>
- <?php do { ?>
- <tr>
- <td><?php echo $row['id'];?></td>
- <td><?php echo $row['category'];?></td>
- <td><?php echo $row['style'];?></td>
- <td><?php echo $row['color'];?></td>
- <td><?php echo $row['material'];?></td>
- <td><?php echo $row['size'];?></td>
- <td><?php echo $row['price'];?></td>
- <td><?php echo $row['image'];?></td>
- <td><?php echo $row['position'];?></td>
- <td><?php echo $row['caption'];?></td>
- <td><?php echo $row['visible'];?></td>
- </tr>
- <?php } while ($row = $stmt->fetch()); ?>
- </table>
- <?php } else {
- echo '<p>No results found.</p>';
- }}
- } ?>
- </body>
- </html>
Add Comment
Please, Sign In to add comment