-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmovies.php
222 lines (142 loc) · 6.7 KB
/
movies.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
<?php
require_once 'conn.php';
require_once 'login.php';
if (isset($_POST['liked'])) {
$pelid = $_POST['pelid'];
$result = mysqli_query($conn, "SELECT * FROM pelicula WHERE id=$pelid");
$row = mysqli_fetch_array($result);
$n = $row['likes'];
mysqli_query($conn, "INSERT INTO likes (pelid, userid) VALUES ($pelid,{$_SESSION['user']})");
mysqli_query($conn, "UPDATE pelicula SET likes=$n+1 WHERE id=$pelid");
echo $n+1;
exit();
}
if (isset($_POST['unliked'])) {
$pelid = $_POST['pelid'];
$result = mysqli_query($conn, "SELECT * FROM pelicula WHERE id=$pelid");
$row = mysqli_fetch_array($result);
$n = $row['likes'];
mysqli_query($conn, "DELETE FROM likes WHERE pelid=$pelid AND userid={$_SESSION['user']}");
mysqli_query($conn, "UPDATE pelicula SET likes=$n-1 WHERE id=$pelid");
echo $n-1;
exit();
}
$pelicula = mysqli_query($conn,"SELECT pelicula.id,
pelicula.titulo, pelicula.descripcion, pelicula.url_imagen,
pelicula.anio_estreno,pais.nombre_pais, pelicula.director,
pelicula.url_trailer, pelicula.likes, genero.nombre_genero, distribuidora.nombre_empresa
FROM pelicula
LEFT JOIN genero
ON pelicula.genero_idgenero = genero.idgenero
LEFT JOIN pais
ON pelicula.idpais = pais.idpais
LEFT JOIN distribuidora
ON pelicula.iddistribuidora = distribuidora.iddistribuidora
");
//echo '<pre>', print_r($peliculas, true), '</pre>';
//die();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Peliculas</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" />
<style>
.like, .unlike, .likes_count {
color: blue;
}
.hide {
display: none;
}
.fa-thumbs-up, .fa-thumbs-o-up {
transform: rotateY(-180deg);
font-size: 1.3em;
}
</style>
</head>
<body>
<?php while ($row = mysqli_fetch_array($pelicula)) { ?>
<div class="pelicula">
<div class="container-fluid">
<div class="row mt-4">
<h1><?php echo $row['titulo'];?></h1>
<div class="col-8 col-sm-7 col-md-3">
<img src="<?php echo $row['url_imagen'] ?>" alt="" width="100%" height="500">
</div>
<div class="col-12 col-sm-5 col-md-2">
<p>Género: <?php echo $row['nombre_genero']; ?></p>
<p>Pais: <?php echo $row['nombre_pais']; ?></p>
<p>Año de estreno: <?php echo $row['anio_estreno']; ?></p>
<p>Dirigida por: <?php echo $row['director']; ?></p>
<p>Distribuida por: <?php echo $row['nombre_empresa']; ?></p>
<a class="btn btn-primary mt-3" href=<?php echo $row['url_trailer']; ?> target="blank" role="button">Ver Trailer</a>
</div>
<div class="col-12 col-sm-8 col-md-5">
<h3 class="mt-3">SINOPSIS</h3>
<p><?php echo $row['descripcion']; ?></p>
</div>
<div class="col-12 col-sm-3 col-md-2">
<p>jijrijrijriji</p>
<?php $results = mysqli_query($conn, "SELECT * FROM likes WHERE userid={$_SESSION['user']} AND pelid=".$row['id']."");
if (mysqli_num_rows($results) == 1 ): ?>
<!-- user already likes post -->
<span class="unlike fa fa-thumbs-up" data-id="<?php echo $row['id']; ?>"></span>
<span class="like hide fa fa-thumbs-o-up" data-id="<?php echo $row['id']; ?>"></span>
<?php else: ?>
<!-- user has not yet liked post -->
<span class="like fa fa-thumbs-o-up" data-id="<?php echo $row['id']; ?>"></span>
<span class="unlike hide fa fa-thumbs-up" data-id="<?php echo $row['id']; ?>"></span>
<?php endif ?>
<span class="likes_count"><?php echo $row['likes']; ?> likes</span>
</div>
</div>
</div>
</div>
<?php } ?>
<script src="jquery.min.js"></script>
<script>
$(document).ready(function(){
// when the user clicks on like
$('.like').on('click', function(){
var pelid = $(this).data('id');
$post = $(this);
$.ajax({
url: 'movies.php',
type: 'post',
data: {
'liked': 1,
'pelid': pelid
},
success: function(response){
$post.parent().find('span.likes_count').text(response + " likes");
$post.addClass('hide');
$post.siblings().removeClass('hide');
}
});
});
// when the user clicks on unlike
$('.unlike').on('click', function(){
var pelid = $(this).data('id');
$post = $(this);
$.ajax({
url: 'movies.php',
type: 'post',
data: {
'unliked': 1,
'pelid': pelid
},
success: function(response){
$post.parent().find('span.likes_count').text(response + " likes");
$post.addClass('hide');
$post.siblings().removeClass('hide');
}
});
});
});
</script>
</body>
</html>