-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomment.php
62 lines (61 loc) · 1.78 KB
/
comment.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
<?php
//
//
if(!empty($_SESSION['roles'])){
include('form_add_com.php');
}
if (empty($_GET['page_com'])){
$page_com = 1;
}else{
$page_com = $_GET['page_com'];
}
include('connect_db.php');
$sql = "SELECT COUNT(*) FROM comment WHERE post_id =:id AND lang= :lang";
$result = $DBH->prepare($sql);
$result->bindValue(':id',$id);
$result->bindValue(':lang',$lang);
$result->execute();
$number_of_rows = $result->fetchColumn();
$m = $number_of_rows;
$posts = $m;
$total = (int)(($posts - 1) / 10) + 1;
$page_com = (int)($page_com);
if(empty($page_com) or $page_com < 0){
$page_com = 1;
}
if($page_com > $total){
$page_com = $total;
}
$max = $page_com*10;
$min = $page_com*10 - 10;
if ($min < 0){
$min = 0;
}
$SQL = "SELECT * FROM comment WHERE post_id =:id AND lang= :lang LIMIT ".$min.", 10 " ;
$STH = $DBH->prepare($SQL);
$STH->bindValue(':id',$id);
$STH->bindValue(':lang',$lang);
$STH->execute();
while($row = $STH->fetch(PDO::FETCH_ASSOC)){
echo '<div class="post">';
echo"<b>".$row['title']."</b>";
echo '</div><div class="post">';
echo $row['text'];
echo '</div><div class="post">';
$link_profil="profil.php?id=".$row['author_id'];
echo"<p>".t($lang,'author').":<a href=".$link_profil.">".$row['author']."</a>".t($lang,'date').": ".$row['date']."<p>";
if(!empty($_SESSION['roles'])){
if(in_array('admin',$_SESSION['roles'])){
echo"<p> <a href=delete_comment.php?id=".$row['id'].">".t($lang,'delete')."</a>";
}
}
echo "</div>";
}
$previous_page = $page_com-1;
$next_page = $page_com+1;
$link =$_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING']."&page_com=";
if($m > 10){
echo " <a href=news.php?page_com=".$link.$previous_page.">back </a>
<a href=news.php?page_com=".$link.$next_page.">next </a></div>";
}
?>