forked from if-itb/IF3110-2015-T1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquestion.php
145 lines (138 loc) · 5.79 KB
/
question.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Simple Stack Exchange</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
<script src="js/thescript.js"></script>
<?php require_once('dbconnect.php'); ?>
</head>
<body>
<div id="wrapper">
<div id="header">
<div id="title">
<a href="index.php" class="center"><p>Simple StackExchange</p></a>
</div>
</div>
<?php
$id = $_GET['id'];
$sql = "SELECT
question.id as id,
question.name as name,
question.email as email,
question.qtopic as qtopic,
question.content as content,
question.vote as vote
FROM question WHERE question.id='$id'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
?>
<div class="contents">
<div class="questioncontent">
<div class="qtitle">
<h1><p><?= $row["qtopic"]?></p></h1>
</div>
<hr>
<div class="thecontent">
<div class="votecontent">
<div class="votebutton">
<div class="upbutton" onclick="changeVote('up',<?=$row['id']?>,'q')">
<img src="assets/upbutton.png" class="buttonimg">
</div>
<div class="votenumber" id="qvote<?=$row['id']?>">
<?= $row["vote"] ?>
</div>
<div class="downbutton" onclick="changeVote('down',<?=$row['id']?>,'q')">
<img src="assets/downbutton.png" class="buttonimg">
</div>
</div>
</div>
<div class="qcontent">
<?= $row["content"]?>
</div>
</div>
<div class="qmetaq">
Asked by <span><?= $row["email"]?></span> | <a href="askme.php?id=<?=$row['id']?>" class="orange">edit</a> | <a href="deletequestion.php?id=<?=$row['id']?>" class="delete red">delete</a>
</div>
</div>
<?php
}
} else {
header("Location: index.php");
exit;
}
?>
<?php
$sql= "SELECT
answers.id as aid,
answers.name as aname,
answers.email as aemail,
answers.a_content as acontent,
answers.vote as avote
FROM
question INNER JOIN answers
ON
answers.qid=question.id
WHERE
question.id='$id'";
$result = $conn->query($sql);
if ($result->num_rows == 0) {
echo"<br>";
echo"<br>";
echo"<h2>There is no answer.. be the first to answer this question!</h2>";
} else
if ($result->num_rows > 0) {
$result_list = array();
while($row = $result->fetch_assoc()) {
$result_list[] = $row;
}
?>
<div class="qtitle">
<h1><p><?= $result->num_rows ?> Answers</p></h1>
<hr>
</div>
<?php
foreach($result_list as $row) { ?>
<div class="answercontent">
<div class="thecontent">
<div class="votecontent">
<div class="votebutton">
<div class="upbutton" onclick="changeVote('up',<?=$row['aid']?>,'a')">
<img src="assets/upbutton.png" class="buttonimg">
</div>
<div class="votenumber" id="avote<?=$row['aid']?>">
<?= $row['avote'] ?>
</div>
<div class="downbutton" onclick="changeVote('down',<?=$row['aid']?>,'a')">
<img src="assets/downbutton.png" class="buttonimg">
</div>
</div>
</div>
<div class="qcontent">
<?= $row['acontent'] ?>
</div>
</div>
<div class="qmetaq">
Answered by <?= $row['aemail'] ?>
</div>
<hr>
</div>
<?php
}
}
?>
<div class="answerForm">
<div class="atitle"><h1>Your Answer</h1></div>
<form name="qForm" action="insertanswer.php" onsubmit="return validateAForm()" method="post" id="questions_form">
<input type="hidden" name="qid" value="<?= $id ?>">
<div><input class="formBar" type="text" name="name" placeholder=" Name"></div>
<div><input class="formBar" type="text" name="email" placeholder=" E-mail"></div>
<div><textarea class="formBar" name="content" form="questions_form" rows="8" placeholder=" Content"></textarea></div>
<input id="postQuestion" type="submit" value="POST">
</form>
</div>
</div>
</div>
</body>
</html>