Guest User

Untitled

a guest
Jan 20th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.56 KB | None | 0 0
  1. <?php
  2. if(isset($_GET['search'])) {
  3. try {
  4. $dsn = 'mysql:host=localhost;dbname=bajan_glasses';
  5. $db = new PDO($dsn, 'glasses_cms', '8019');
  6.  
  7. $sql = 'SELECT id, category, style, color, material, size, price, image,
  8. position, caption, visible
  9.  
  10. FROM eyeglasses
  11. WHERE id LIKE id AND category = category AND style = style AND
  12. color = color
  13. AND material = material AND size = size AND price = price AND
  14. image = image AND position = position
  15. AND caption = caption AND visible = visible
  16. ORDER BY id';
  17. // <!--------------------- when ":" is added to the above , the table
  18. does not display------------->
  19.  
  20. $stmt = $db->prepare($sql);
  21. $stmt->bindValue(':id', '%' . $_GET['id'] . '%');
  22. // $stmt->bindParam(':id', $_GET['id'], PDO::PARAM_INT);
  23. $stmt->bindParam(':category', $_GET['category'], PDO::PARAM_STR);
  24. $stmt->bindParam(':style', $_GET['style'], PDO::PARAM_STR);
  25. $stmt->bindParam(':color', $_GET['color'], PDO::PARAM_STR);
  26. $stmt->bindParam(':material', $_GET['material'], PDO::PARAM_STR);
  27. $stmt->bindParam(':size', $_GET['size'], PDO::PARAM_INT);
  28. $stmt->bindParam(':price', $_GET['price'], PDO::PARAM_INT);
  29. $stmt->bindParam(':image', $_GET['image'], PDO::PARAM_INT);
  30. $stmt->bindParam(':position', $_GET['position'], PDO::PARAM_INT);
  31. $stmt->bindParam(':caption', $_GET['caption'], PDO::PARAM_STR);
  32. $stmt->bindParam(':visible', $_GET['visible'], PDO::PARAM_INT);
  33.  
  34. // $stmt->execute('bindParam'); // use://if still getting token error.
  35. $stmt->execute();
  36.  
  37. if (isset($errorInfo[2])) {
  38. $error = $errorInfo[2];
  39. }
  40. } catch (Exception $e) {
  41.  
  42. $error = $e->getMessage();
  43. }
  44. }
  45.  
  46. ?>
  47.  
  48.  
  49.  
  50. <!DOCTYPE html>
  51. <html>
  52. <head>
  53. <meta charset="UTF-8">
  54. <title>PDO: SELECT Loop</title>
  55. <link href="../../styles/styles.css" rel="stylesheet" type="text/css">
  56. </head>
  57. <body>
  58.  
  59.  
  60.  
  61. <form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">
  62.  
  63.  
  64.  
  65.  
  66. <fieldset>
  67.  
  68. <p>
  69.  
  70. <label for="id">id </label>
  71. <select name="id" id="id">
  72. <?php
  73.  
  74. //$material = array('woo' => 'wood');
  75. //$material = array('ace' => 'acetate');
  76. ///$material = array('pla' => 'plastic');
  77. //$material = array('ste' => 'steel');
  78.  
  79.  
  80.  
  81. for ($id =0; $id <=1 ; $id++) {
  82. echo "<option>$id</option>";
  83. };
  84.  
  85. ?>
  86.  
  87.  
  88.  
  89. </select>
  90.  
  91.  
  92.  
  93.  
  94. <label for="category ">category </label>
  95. <select name="category " id="category ">
  96.  
  97.  
  98. <option> </option>
  99. <option>men</option>
  100. <option>women</option>
  101. <option>children</option>
  102.  
  103. </select>
  104.  
  105.  
  106.  
  107.  
  108. <label for="style ">style </label>
  109. <select name="style " id="style ">
  110.  
  111.  
  112. <option selected value="style">style</option>
  113. <option>aviator</option>
  114. <option>rectangular</option>
  115. <option>round</option>
  116. <option>square</option>
  117. <option>vintage</option>
  118. <option>black</option>
  119.  
  120.  
  121. </select>
  122.  
  123.  
  124.  
  125.  
  126. <label for="color ">color </label>
  127. <select name="color " id="color ">
  128.  
  129.  
  130. <option></option>
  131. <option>white</option>
  132. <option>blue</option>
  133. <option>green</option>
  134. <option>yellow</option>
  135. <option>brown</option>
  136. <option>black</option>
  137. <option>red</option>
  138. <option>pink</option>
  139. <option>pink</option>
  140.  
  141. </select>
  142.  
  143.  
  144. <label for="material">Material </label>
  145. <select name="material" id="material">
  146. <?php
  147.  
  148. //$material = array('woo' => 'wood');
  149. //$material = array('ace' => 'acetate');
  150. ///$material = array('pla' => 'plastic');
  151. //$material = array('ste' => 'steel');
  152.  
  153.  
  154.  
  155. // for ($material = 'wood'+'steel'; $material <= 'plastic'; $material++)
  156. {
  157. // echo "<option>$material</option>";
  158. // };
  159.  
  160. ?>
  161.  
  162. <option> </option>
  163. <option>wood</option>
  164. <option>acetate</option>
  165. <option>plastic </option>
  166. <option>steel </option>
  167. </select>
  168.  
  169.  
  170.  
  171.  
  172. <label for="size">size </label>
  173. <select name="size" id="size">
  174. <?php
  175.  
  176. $size = array('sma' => 'small');
  177. $size = array('med' => 'medium');
  178. $size = array('lar' => 'large');
  179.  
  180.  
  181. for ($size= 'small'; $size<= 'medium'; $size++) {
  182. echo "<option>$size</option>";
  183.  
  184. };
  185.  
  186. ?>
  187.  
  188. <option> </option>
  189. <option>small</option>
  190. <option>medium</option>
  191. <option>large</option>
  192.  
  193. </select>
  194.  
  195.  
  196. <label for="price ">price</label>
  197. <select name="price " id="price ">
  198.  
  199.  
  200. <option selected value="price"></option>
  201. <option>$199</option>
  202. <option>rectangular</option>
  203. <option>$259</option>
  204. <option>$129</option>
  205. <option>$111</option>
  206. <option>$111</option>
  207.  
  208.  
  209. </select>
  210.  
  211.  
  212.  
  213.  
  214. <label for="style ">image </label>
  215. <select name="image " id="image ">
  216.  
  217.  
  218. <option ></option>
  219.  
  220.  
  221.  
  222. </select>
  223.  
  224.  
  225.  
  226.  
  227. <label for="style ">position</label>
  228. <select name="style " id="style ">
  229.  
  230.  
  231. <option selected value="position"></option>
  232. <option>1</option>
  233. <option>2</option>
  234. <option>3</option>
  235.  
  236.  
  237.  
  238. </select>
  239.  
  240.  
  241.  
  242. <label for="style ">caption</label>
  243. <select name="style " id="style ">
  244.  
  245.  
  246. <option selected value="style"></option>
  247. <option>Choose from Mens styles...</option>
  248. <option>men glasses</option>
  249. <option>women glasses</option>
  250. <option> children glasses...</option>
  251.  
  252.  
  253.  
  254. </select>
  255.  
  256.  
  257.  
  258.  
  259. <label for="visible ">visible </label>
  260. <select name="visible " id="visible ">
  261.  
  262.  
  263.  
  264. <option></option>
  265. <option>1</option>
  266. <option>2</option>
  267. <option>3</option>
  268.  
  269.  
  270.  
  271. </select>
  272.  
  273.  
  274.  
  275. <input type="submit" name="search" value="Search">
  276. </p>
  277. </fieldset>
  278. </form>
  279.  
  280. <?php if (isset($_GET['search'])) {
  281. $row = $stmt->fetch();
  282. if ($row) {
  283.  
  284. ?>
  285. <table>
  286. <tr>
  287. <th>id</th>
  288. <th>category</th>
  289. <th>style</th>
  290. <th>color</th>
  291. <th>material</th>
  292. <th>size</th>
  293. <th>price</th>
  294. <th>image</th>
  295. <th>position</th>
  296. <th>caption</th>
  297. <th>visible</th>
  298.  
  299. </tr>
  300. <?php /******** foreach ($db->query($sql) as $row) {*********/?>
  301. <?php do { ?>
  302. <tr>
  303. <td><?php echo $row['id'];?></td>
  304. <td><?php echo $row['category'];?></td>
  305. <td><?php echo $row['style'];?></td>
  306. <td><?php echo $row['color'];?></td>
  307. <td><?php echo $row['material'];?></td>
  308. <td><?php echo $row['size'];?></td>
  309. <td><?php echo $row['price'];?></td>
  310. <td><?php echo $row['image'];?></td>
  311. <td><?php echo $row['position'];?></td>
  312. <td><?php echo $row['caption'];?></td>
  313. <td><?php echo $row['visible'];?></td>
  314. </tr>
  315.  
  316. <?php } while ($row = $stmt->fetch()); ?>
  317. </table>
  318. <?php } else {
  319. echo '<p>No results found.</p>';
  320. }}
  321. } ?>
  322. </body>
  323. </html>
Add Comment
Please, Sign In to add comment