-
Notifications
You must be signed in to change notification settings - Fork 0
/
single.php
120 lines (96 loc) · 3.13 KB
/
single.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
<?php
$page = 'single';
$masterpiece= $_GET['mastid'];
require_once('includes/header.php');
include('includes/parse-comment.php');
$user_id = $_SESSION['user_id'];
$query = "SELECT m.*, c.*
FROM masterpieces AS m, categories AS c , masterpieces_categories AS m_c
WHERE m.master_id = $masterpiece
AND m.master_id = m_c.master_id
AND c.category_id = m_c.category_id
LIMIT 1";
$result= $db->query($query);
$row = $result->fetch_assoc();
?>
<section class="user cf">
<article>
<a href="profile.php"><img src="<?php show_avatar($user_id); ?>"></a>
<h1> <?php show_username($user_id); ?> </h1>
</article>
</section>
<main class="cf">
<h1><?php echo $row['title']; ?></h1>
<h2><a href="category.php?catid=<?php echo $row['category_id']; ?>"> < Back to <?php echo $row['name']; ?></a></h2>
<a href="single.php?mastid=<?php echo $row['master_id']; ?>">
<img src="<?php echo $row['images']; ?>">
</a>
<p><?php echo $row['description']; ?></p>
<ul class="sinfo">
<?php $query_cat="SELECT c.name , c.category_id
FROM categories AS c, masterpieces_categories AS m_c
WHERE m_c.master_id = $masterpiece
AND c.category_id = m_c.category_id";
$result_cat= $db->query($query_cat);
?>
<li>Category:<?php while( $row_cat = $result_cat->fetch_assoc() ){ ?>
<a href="category.php?catid=<?php echo $row_cat['category_id']; ?>">
<?php echo $row_cat['name']; ?></a>
<?php }//end while loop ?>
</li>
<li>Posted:<?php echo convert_date($row['date']); ?></li>
</ul>
<section class="comments">
<?php //get all the comments about this post
$query_comments = "SELECT comments.* ,users.username
FROM comments, users
WHERE comments.master_id = $masterpiece
AND users.user_id = comments.user_id
ORDER BY comments.date ASC";
//run it!
$result_comments = $db->query($query_comments);
//check to see if any comments found
if( $result_comments->num_rows >= 1 ){
?>
<?php while( $row_comments = $result_comments->fetch_assoc() ){?>
<figure class="comment">
<h3><?php echo $row_comments['username']; ?>:</h3>
<p><?php echo $row_comments['body']; ?></p>
<ul class="date cf">
<li><?php echo convert_date($row['date']); ?></li>
</ul>
</figure>
<?php }//end while
}//end if comments were found
else{
echo 'There are no comments yet. Leave one!';
}
?>
<?php //show feedback message if it exists
if ($_SESSION['logged_in']) {
if( isset($message) ){
?>
<div class="<?php echo $status; ?> message">
<?php
echo $message;
//check to see if there were validation errors
if(isset($errors)){ ?>
<ul id ="errors">
<?php foreach( $errors as $error ){ ?>
<li><?php echo $error; ?></li>
<?php } ?>
</ul>
<?php } //end if validation errors exist ?>
</div>
<?php }//end if message exists ?>
<form action="#leavecomment" method="post">
<label for="body">Leave a comment:</label>
<textarea name="body" id="body"></textarea>
<input type="submit" value="Submit Comment">
<input type="hidden" name="did_comment" value="true">
</form><?php }else{
echo 'You must be logged in to leave a comment.';
} ?>
</section>
</main>
<?php include('includes/footer.php'); ?>