Advertisement
Guest User

Untitled

a guest
Feb 18th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.40 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title> Queery </title>
  5. <style>
  6. #wrap {
  7. display:inline-block;
  8. width=100%;
  9. margin:0 auto;
  10. }
  11. #left_col {
  12. float:left;
  13. width:500px;
  14. }
  15. #right_col {
  16. float:left;
  17. width:500px;
  18. }
  19. table, th, td {
  20. border: 1px solid black;
  21. }
  22. </style>
  23. </head>
  24. <body>
  25. <?php
  26. //1.Create database connection
  27. $dbhost="localhost";
  28. $dbuser="root";
  29. $dbpass="";
  30. $dbname="classicmodels";
  31.  
  32. $conn = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
  33.  
  34. // define variables and set to empty values
  35. $orderNumber=$startDate=$endDate = "";
  36. $columns = $_POST["check_list"];
  37.  
  38. if ($_SERVER["REQUEST_METHOD"] == "POST") {
  39. $orderNumber = $_POST["orderNumber"];
  40. $startDate = $_POST["startDate"];
  41. $endDate = $_POST["endDate"];
  42. }
  43.  
  44. // Check connection
  45. if ($conn->connect_error) {
  46. die("Connection failed: " . $conn->connect_error);
  47. }
  48. foreach($columns as $column){
  49. $cols .= $column . ",";
  50. }
  51. $sql = "SELECT " . $cols . "FROM orderdetails,orders,products ";
  52. $result = $conn->query($sql);
  53.  
  54.  
  55. ?>
  56. <h1>Query</h1>
  57.  
  58. <div id="wrap">
  59. <div id="left_col">
  60. <h2> Select Order Parameters </h2>
  61. <!-Input fields->
  62. <form action="dbqueery2.php" method="post">
  63. Order Number: <input type="text" name="orderNumber"> or <br> <br>
  64. Order Date (YYYY-MM-DD) <br>
  65. from: <input type="text" name="startDate"> to: <input type="text" name="endDate"> <br>
  66. <br><br><br><input type="submit"> <br>
  67. </div>
  68.  
  69. <div id="right_col">
  70. <h2> Select Columns to Display </h2>
  71. <input type="checkbox" name="check_list[]" value=<?php "{row["orderNumber"]}" ?> > Order Number<br>
  72. <input type="checkbox" name="check_list[]" value=<?php "{row["orderDate"]}" ?>> Order Date<br>
  73. <input type="checkbox" name="check_list[]" value=<?php "{row["shippedDate"]}" ?>> Shipped Date<br>
  74. <input type="checkbox" name="check_list[]" value=<?php "{row["productName"]}" ?>> Product Name<br>
  75. <input type="checkbox" name="check_list[]" value=<?php "{row["productDescription"]}" ?>> Product Description<br>
  76. <input type="checkbox" name="check_list[]" value=<?php "{row["quantityOrdered"]}" ?>> Quantity Ordered<br>
  77. <input type="checkbox" name="check_list[]" value=<?php "{row["priceEach"]}" ?>> Price Each<br>
  78. </form>
  79. </div>
  80.  
  81. </div>
  82. <h3> SQL Query </h3>
  83. <?php
  84. echo "<b>SELECT </b>". $orderNumber ;
  85. //3.Use returned data(if any)
  86. while ($row=mysqli_fetch_assoc($result)){
  87. echo "<tr>";
  88. foreach($row as $value){
  89. echo "<td>".stripslashes($value). "</td>";
  90. }
  91. }
  92.  
  93. // if ($result->num_rows > 0) {
  94. // echo "<table><tr>
  95. // <th>ID</th>
  96. // <th>Name</th></tr>";
  97. // // output data of each row
  98. // while($row = $result->fetch_assoc()) {
  99. // echo "<tr><td>".$row["orderNumber"]."</td><td>"
  100. // .$row["orderLineNumber"]
  101. // . "</td></tr>";
  102. // }
  103. // echo "</table>";
  104. // } else {
  105. // echo "0 results";
  106. // }
  107.  
  108.  
  109.  
  110. //4.Release returned data
  111. mysqli_free_result($result);
  112. ?>
  113. </body>
  114. </html>
  115.  
  116. <?php
  117. //5. Close database connection
  118. mysqli_close($conn);
  119. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement