-
Notifications
You must be signed in to change notification settings - Fork 0
/
ask_question.php
133 lines (107 loc) · 4.03 KB
/
ask_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
<?php
include('includes/connect.php');
include('includes/header.php');
//ago Function
function TimeAgo ($oldTime, $newTime) {
$timeCalc = strtotime($newTime) - strtotime($oldTime);
if ($timeCalc >= (60*60*24*30*12*2)){
$timeCalc = intval($timeCalc/60/60/24/30/12) . " years ago";
}else if ($timeCalc >= (60*60*24*30*12)){
$timeCalc = intval($timeCalc/60/60/24/30/12) . " year ago";
}else if ($timeCalc >= (60*60*24*30*2)){
$timeCalc = intval($timeCalc/60/60/24/30) . " months ago";
}else if ($timeCalc >= (60*60*24*30)){
$timeCalc = intval($timeCalc/60/60/24/30) . " month ago";
}else if ($timeCalc >= (60*60*24*2)){
$timeCalc = intval($timeCalc/60/60/24) . " days ago";
}else if ($timeCalc >= (60*60*24)){
$timeCalc = " Yesterday";
}else if ($timeCalc >= (60*60*2)){
$timeCalc = intval($timeCalc/60/60) . " hours ago";
}else if ($timeCalc >= (60*60)){
$timeCalc = intval($timeCalc/60/60) . " hour ago";
}else if ($timeCalc >= 60*2){
$timeCalc = intval($timeCalc/60) . " minutes ago";
}else if ($timeCalc >= 60){
$timeCalc = intval($timeCalc/60) . " minute ago";
}else if ($timeCalc > 0){
$timeCalc .= " seconds ago";
}
return $timeCalc;
}
/*######################################### ADD POST BY USER#######################*/
if(isset($_POST['post']))
{
if(isset($_SESSION['email']))
{
$post_content=$_POST['post_content'];
$query="insert into post (content,ask_by,poster_email) values('$post_content','".$_SESSION['name']."','".$_SESSION['email']."')";
$sql=mysqli_query($con,$query);
}
else
{?>
<script src="js/sweetalert.min.js"></script>
<script>
swal("You Can't Ask Your Question !", "Login Or Signin to Ask Your Quesrtion !", "warning");
</script>
<?php }
}
?>
<div class="post_section">
<div class="container">
<div class="row">
<div class="col-lg-12 col-sm-8 post_left">
<div class="comments_form">
<h3>Ask A Question</h3>
<form class="form q" method="post">
<div class="full">
<textarea rows="5" name="post_content" cols="10" class="form-control" placeholder="Ask a Question.."></textarea>
</div>
<input name="post" type="submit" class="commonBtn" value="Ask">
</form>
</div>
</div>
<div class="col-lg-12 col-sm-8 post_left">
<div class="post_left_section post_right_border">
<!--end post-->
<div class="related_post_sec single_post">
<h3>More Questions</h3>
<ul>
<?php
$query="select * from post ORDER BY post_id DESC";
$sql=mysqli_query($con,$query);
while($row=mysqli_fetch_array($sql)){
$id=$row['post_id'];
?>
<li>
<?php
$comment_query="select * from comment where post_id='$id'";
$csql=mysqli_query($con,$comment_query);
$count=mysqli_num_rows($csql);
?>
<div class="rel_right">
<h4><a href="ask_question_comments.php?postid=<?php echo $id ?>"><?php echo $row['content']; ?></a></h4>
<div class="meta">
<span class="author">By: <a><?php echo $row['ask_by'] ?></a></span>
<span class="date">Posted: <a><?php echo TimeAgo($row['date'], date("Y-m-d H:i:s")); ?></a></span>
</div>
<div class="post_bottom">
<ul>
<li class="like">
<a href="ask_question_comments.php?postid=<?php echo $id ?>">
<img src="img/news/like_icon.png" alt="">
<span><?php echo $count; ?></span>
</a>
</li>
</ul>
</div>
</div><!--end rel right-->
</li>
<?php } ?>
</div><!--end post left section-->
</div><!--end post_left-->
<!--end post_right-->
</div>
</div>
</div>
<?php include('includes/footer.php');?>