-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetStarted.php
More file actions
109 lines (98 loc) · 4.24 KB
/
Copy pathgetStarted.php
File metadata and controls
109 lines (98 loc) · 4.24 KB
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
<?php
function limitWords($string, $word_limit)
{
$words = explode(" ", $string);
return implode(" ", array_slice($words, 0, $word_limit)) . (count($words) > $word_limit ? "..." : "");
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>TechQuery-Hub</title>
<link rel="stylesheet" href="css/header.css">
<link rel="stylesheet" href="css/getStarted.css">
<link rel="stylesheet" href="css/sidebar.css">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link
href="https://fonts.googleapis.com/css2?family=Calistoga&family=DM+Serif+Text:ital@0;1&family=Eczar:wght@400..800&family=Forum&family=Macondo&display=swap"
rel="stylesheet">
</head>
<body>
<div class="fixed">
<?php include "includes/header.php"; ?>
</div>
<!-- sidebar -->
<?php include "includes/sidebar.php"; ?>
<!-- side bar ends -->
<div style="padding-top:60px ;">
<div class="content">
<h4>All questions</h4>
<?php if (isset($row['user_id'])): ?>
<a href="askquestion.php" class="btn">Ask question</a>
<?php else: ?>
<a href="" class="btn">Ask question</a>
<?php endif; ?>
</div>
</div>
<!-- card -->
<?php
// Include the database configuration file
// Execute the SQL query to fetch data
$stmt = $admin->ret("SELECT q.questionid, q.title, q.description AS `desc`, q.questioneddate, u.username AS username, GROUP_CONCAT(t.tagname SEPARATOR ',') AS tags
FROM questions AS q
JOIN questiontag AS qt ON q.questionid = qt.questionid
JOIN tags AS t ON qt.tagid = t.tagid
JOIN users AS u ON q.user_id = u.user_id
GROUP BY q.questionid
ORDER BY q.questioneddate DESC");
// Check if there are any rows fetched
if ($stmt) {
// Loop through each fetched row
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
// Fetch the count of answers for this question
$stma = $admin->ret("SELECT COUNT(*) AS answer_count
FROM `answers`
WHERE `questionid` = '{$row['questionid']}'");
$acount = $stma->fetch(PDO::FETCH_ASSOC)['answer_count'];
?>
<div class="card">
<div class="cardsec1">
<p style="margin: 3px;color: #6696de;">✨ Question </p>
<p style="margin: 3px;color: aquamarine;"><?php echo $acount ?> Answers</p> <!-- Corrected here -->
</div>
<div class="cardsec2">
<div style="word-spacing: 1px;letter-spacing: 1px;display:flex;"><a
href="preview.php?question_id=<?php echo $row['questionid']; ?>&qusername=<?php echo $row['username']; ?>"
style="margin:3px;">Title <?php echo $row['title']; ?></a>
</div>
<div
style="width:100%;font-size: small; color: gray;font-family:'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;">
<?php echo limitWords($row['desc'], 50); ?>
</div>
<div class="btnasked">
<div>
<?php
// Loop through tags for this question
$tags = explode(',', $row['tags']);
foreach ($tags as $tag) {
echo '<button class="tagbtn">' . $tag . '</button>';
}
?>
</div>
<div class="qasked"><?php echo $row['username']; ?> Asked on <?php echo $row['questioneddate']; ?>
</div>
</div>
</div>
</div>
<?php
}
} else {
// If no rows are fetched, display a message or take appropriate action
echo "No questions found.";
}
?>
</body>
</html>