Advertisement
Guest User

Untitled

a guest
Sep 3rd, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.65 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <?php
  5. $servername = "localhost";
  6. $password = "*****";
  7. $dbname = "the_database";
  8. $conn = new mysqli($servername, $username, $password, $dbname);
  9. if ($conn->connect_error) {
  10. die("Connection failed: " . $conn->connect_error);
  11. }
  12. $sql = "SELECT * FROM input";
  13. $result = $conn->query($sql);
  14. ?>
  15. <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  16. <link rel="stylesheet" type="text/css" href="css/normalize.css" />
  17. <style>
  18. .name {
  19. width: 700px;
  20. margin-top: 1%;
  21. margin-left: 20%;
  22. padding-left:2%;
  23. padding-right:2%;
  24. padding-top:10%;
  25. margin-right: 35%;
  26. word-wrap: break-word;
  27. }
  28. textarea#addtext{
  29. width:600px;
  30. height:100px;
  31. }
  32. </style>
  33. <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.js">
  34. </script>
  35. <script type='text/javascript'>//<![CDATA[
  36. $(window).load(function(){
  37. $().ready = function() {
  38. $('#addtext').hide();
  39. $('#addsubmit').hide();
  40. $("#add").click(function() {
  41. $('#add').hide();
  42. $('#addtext').fadeIn('slow').focus();
  43. $('#addsubmit').fadeIn('slow');
  44. });
  45.  
  46. $('#addtext').blur(function(){
  47. $('#addtext').hide();
  48. $('#addsubmit').hide();
  49. $('#add').fadeIn('slow');
  50. });
  51. }();
  52. });//]]>
  53.  
  54. </script>
  55. </style>
  56. </head>
  57. <body>
  58.  
  59. <div class="name">
  60.  
  61. <?php
  62. if ($result->num_rows > 0) {
  63. while($row = $result->fetch_assoc()) { ?>
  64.  
  65. <div id="q">
  66. <B><big><font color= #ba4a00> Q:</font></big> <?php echo $row["question"]; ?> </B></br>
  67. <B><small><font color= #ba4a00> Description:</font> <?php echo $row["description"]; ?> </small></B></br>
  68. <p id="tag1"><small> <?php echo $row["subject"]; ?> </small></p><p id="tag2"><small> <?php echo $row["sub_subject"]; ?> </small></p>
  69. <button class="addanswer" id="add"><B>Add Answer</B></button>
  70. <form>
  71. <textarea class="addtext" name="addtext" required id="addtext" placeholder="Please type your question here.."></textarea>
  72. <button class="addanswer" id="addsubmit"><B>Submit</B></button>
  73. </form>
  74. <small><p><?php echo $row["date"]; ?></p></small>
  75. </div>
  76. <?php }
  77. } else {
  78. echo "0 results";
  79. }
  80. $conn->close();
  81. ?>
  82. </div>
  83.  
  84. </body>
  85. </html>
  86.  
  87. <!DOCTYPE html>
  88. <html lang="en">
  89. <head>
  90. <?php
  91. $servername = "localhost";
  92. $username = "root";
  93. $password = "******";
  94. $dbname = "the_database";
  95. $conn = new mysqli($servername, $username, $password, $dbname);
  96. if ($conn->connect_error) {
  97. die("Connection failed: " . $conn->connect_error);
  98. }
  99. $sql = "SELECT * FROM input";
  100. $result = $conn->query($sql);
  101. ?>
  102. <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  103. <link rel="stylesheet" type="text/css" href="css/normalize.css" />
  104. <style>
  105. .name {
  106. width: 700px;
  107. margin-top: 1%;
  108. margin-left: 20%;
  109. padding-left:2%;
  110. padding-right:2%;
  111. padding-top:10%;
  112. margin-right: 35%;
  113. word-wrap: break-word;
  114. }
  115. textarea#addtext{
  116. width:600px;
  117. height:100px;
  118. }
  119. </style>
  120. <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.js">
  121. </script>
  122. <script type='text/javascript'>
  123. function addanswer(index){
  124. $('#add_' + index).hide();
  125. $('#addtext_' + index).fadeIn('slow').focus();
  126. $('#addsubmit_' + index).fadeIn('slow');
  127. }
  128. </script>
  129. </style>
  130. </head>
  131. <body>
  132.  
  133. <div class="name">
  134.  
  135. <?php
  136. if ($result->num_rows > 0) {
  137. $index = 0;
  138. while($row = $result->fetch_assoc()) {
  139. $index++; // stuff inside foreach goes here
  140. ?>
  141.  
  142. <div id="q">
  143. <B><big><font color= #ba4a00> Q:</font></big> <?php echo $row["question"]; ?> </B></br>
  144. <B><small><font color= #ba4a00> Description:</font> <?php echo $row["description"]; ?> </small></B></br>
  145. <p id="tag1"><small> <?php echo $row["subject"]; ?> </small></p><p id="tag2"><small> <?php echo $row["sub_subject"]; ?> </small></p>
  146. <?php
  147. echo '<button class="add" id="add_'.$index.'"><B>Add</B></button>';
  148. echo '<form style="display:none;" name="answer_'.$index.'" method="post" action="output.php">'; // I dont think openning form from row to row would be nice!
  149. echo '<textarea style="display:none;" type="text" class="addtext" name="addtext" required id="addtext_'.$index.'" placeholder="Please type your question here.."></textarea>';
  150. echo '<button style="display:none;" onClick="addsubmit('.$index.');" type="addsubmit" id="addsubmit_'.$index.'" class="addsubmit"><B>Submit</B></button>';
  151. echo '</form>';
  152. ?>
  153. <small><p><?php echo $row["date"]; ?></p></small>
  154. </div>
  155. <?php }
  156. } else {
  157. echo "0 results";
  158. }
  159. $conn->close();
  160. ?>
  161. </div>
  162.  
  163. </body>
  164. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement