Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <?php
- $servername = "localhost";
- $password = "*****";
- $dbname = "the_database";
- $conn = new mysqli($servername, $username, $password, $dbname);
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- $sql = "SELECT * FROM input";
- $result = $conn->query($sql);
- ?>
- <meta http-equiv="content-type" content="text/html; charset=utf-8" />
- <link rel="stylesheet" type="text/css" href="css/normalize.css" />
- <style>
- .name {
- width: 700px;
- margin-top: 1%;
- margin-left: 20%;
- padding-left:2%;
- padding-right:2%;
- padding-top:10%;
- margin-right: 35%;
- word-wrap: break-word;
- }
- textarea#addtext{
- width:600px;
- height:100px;
- }
- </style>
- <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.js">
- </script>
- <script type='text/javascript'>//<![CDATA[
- $(window).load(function(){
- $().ready = function() {
- $('#addtext').hide();
- $('#addsubmit').hide();
- $("#add").click(function() {
- $('#add').hide();
- $('#addtext').fadeIn('slow').focus();
- $('#addsubmit').fadeIn('slow');
- });
- $('#addtext').blur(function(){
- $('#addtext').hide();
- $('#addsubmit').hide();
- $('#add').fadeIn('slow');
- });
- }();
- });//]]>
- </script>
- </style>
- </head>
- <body>
- <div class="name">
- <?php
- if ($result->num_rows > 0) {
- while($row = $result->fetch_assoc()) { ?>
- <div id="q">
- <B><big><font color= #ba4a00> Q:</font></big> <?php echo $row["question"]; ?> </B></br>
- <B><small><font color= #ba4a00> Description:</font> <?php echo $row["description"]; ?> </small></B></br>
- <p id="tag1"><small> <?php echo $row["subject"]; ?> </small></p><p id="tag2"><small> <?php echo $row["sub_subject"]; ?> </small></p>
- <button class="addanswer" id="add"><B>Add Answer</B></button>
- <form>
- <textarea class="addtext" name="addtext" required id="addtext" placeholder="Please type your question here.."></textarea>
- <button class="addanswer" id="addsubmit"><B>Submit</B></button>
- </form>
- <small><p><?php echo $row["date"]; ?></p></small>
- </div>
- <?php }
- } else {
- echo "0 results";
- }
- $conn->close();
- ?>
- </div>
- </body>
- </html>
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <?php
- $servername = "localhost";
- $username = "root";
- $password = "******";
- $dbname = "the_database";
- $conn = new mysqli($servername, $username, $password, $dbname);
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- $sql = "SELECT * FROM input";
- $result = $conn->query($sql);
- ?>
- <meta http-equiv="content-type" content="text/html; charset=utf-8" />
- <link rel="stylesheet" type="text/css" href="css/normalize.css" />
- <style>
- .name {
- width: 700px;
- margin-top: 1%;
- margin-left: 20%;
- padding-left:2%;
- padding-right:2%;
- padding-top:10%;
- margin-right: 35%;
- word-wrap: break-word;
- }
- textarea#addtext{
- width:600px;
- height:100px;
- }
- </style>
- <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.js">
- </script>
- <script type='text/javascript'>
- function addanswer(index){
- $('#add_' + index).hide();
- $('#addtext_' + index).fadeIn('slow').focus();
- $('#addsubmit_' + index).fadeIn('slow');
- }
- </script>
- </style>
- </head>
- <body>
- <div class="name">
- <?php
- if ($result->num_rows > 0) {
- $index = 0;
- while($row = $result->fetch_assoc()) {
- $index++; // stuff inside foreach goes here
- ?>
- <div id="q">
- <B><big><font color= #ba4a00> Q:</font></big> <?php echo $row["question"]; ?> </B></br>
- <B><small><font color= #ba4a00> Description:</font> <?php echo $row["description"]; ?> </small></B></br>
- <p id="tag1"><small> <?php echo $row["subject"]; ?> </small></p><p id="tag2"><small> <?php echo $row["sub_subject"]; ?> </small></p>
- <?php
- echo '<button class="add" id="add_'.$index.'"><B>Add</B></button>';
- 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!
- echo '<textarea style="display:none;" type="text" class="addtext" name="addtext" required id="addtext_'.$index.'" placeholder="Please type your question here.."></textarea>';
- echo '<button style="display:none;" onClick="addsubmit('.$index.');" type="addsubmit" id="addsubmit_'.$index.'" class="addsubmit"><B>Submit</B></button>';
- echo '</form>';
- ?>
- <small><p><?php echo $row["date"]; ?></p></small>
- </div>
- <?php }
- } else {
- echo "0 results";
- }
- $conn->close();
- ?>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement