-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfive_star_review.php
378 lines (284 loc) · 15.1 KB
/
five_star_review.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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8" />
<title>Review & Rating System in PHP & Mysql using Ajax</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<!-- Font Awesome -->
<link rel="stylesheet" href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css" integrity="sha384-AYmEC3Yw5cVb3ZcuHtOA93w35dYTsvhLPVnYs9eStHfGJvOvKxVfELGroGkvsg+p" crossorigin="anonymous" />
<!-- Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<style>
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@500&display=swap');
* {
margin: 0;
padding: 0;
font-family: 'Poppins', sans-serif;
}
body {
background-image: linear-gradient(to top, #e6e9f0 0%, #eef1f5 100%);
background-repeat: no-repeat;
background-attachment: fixed;
}
.progress-label-left {
float: left;
margin-right: 0.5em;
line-height: 1em;
}
.progress-label-right {
float: right;
margin-left: 0.3em;
line-height: 1em;
}
.star-light {
color: #e9ecef;
}
.row {
display: flex;
justify-content: center;
align-items: center;
padding: 20px;
}
</style>
</head>
<body>
<div class="alert alert-primary" role="alert">
<h1 class="text-center mt-2 mb-2">Product Rating/Review System</h1>
</div>
<div class="container">
<div class="card">
<div class="card-header">Sample Product</div>
<div class="card-body">
<div class="row">
<div class="col-sm-3 text-center">
<?php
$conn = mysqli_connect("localhost", "root", "", "admin1");
// Assuming you have a database connection named $conn
// Assuming $room_id contains the room ID for which you want to fetch the image
$room_id = $_GET['id']; // Example room ID
// SQL query to fetch the image URL for the specific room ID
$query = "SELECT image FROM room_type WHERE room_type_id = $room_id";
$result = mysqli_query($conn, $query);
// Check if the query executed successfully and if it returned any rows
if ($result && mysqli_num_rows($result) > 0) {
$row = mysqli_fetch_assoc($result);
$image_url = $row['image'];
// Output the image tag with the fetched image URL
echo "<img src='img/$image_url' alt='phone' width='230'>";
} else {
// Output a default image or handle the case when no image is found
echo "<img src='default_image.jpg' alt='phone' width='230'>";
}
?>
<button type="button" name="add_review" id="add_review" class="btn btn-primary form-control mt-3">Rate/Review This Product</button>
</div>
<div class="col-sm-4 text-center">
<h1 class="text-warning mt-4 mb-4">
<b><span id="average_rating">0.0</span> / 5</b>
</h1>
<div class="mb-3">
<i class="fas fa-star star-light mr-1 main_star"></i>
<i class="fas fa-star star-light mr-1 main_star"></i>
<i class="fas fa-star star-light mr-1 main_star"></i>
<i class="fas fa-star star-light mr-1 main_star"></i>
<i class="fas fa-star star-light mr-1 main_star"></i>
</div>
<h3><span id="total_review">0</span> Review</h3>
</div>
<div class="col-sm-4">
<p>
<div class="progress-label-left"><b>5</b> <i class="fas fa-star text-warning"></i></div>
<div class="progress-label-right">(<span id="total_five_star_review">0</span>)</div>
<div class="progress">
<div class="progress-bar bg-warning" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" id="five_star_progress"></div>
</div>
</p>
<p>
<div class="progress-label-left"><b>4</b> <i class="fas fa-star text-warning"></i></div>
<div class="progress-label-right">(<span id="total_four_star_review">0</span>)</div>
<div class="progress">
<div class="progress-bar bg-warning" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" id="four_star_progress"></div>
</div>
</p>
<p>
<div class="progress-label-left"><b>3</b> <i class="fas fa-star text-warning"></i></div>
<div class="progress-label-right">(<span id="total_three_star_review">0</span>)</div>
<div class="progress">
<div class="progress-bar bg-warning" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" id="three_star_progress"></div>
</div>
</p>
<p>
<div class="progress-label-left"><b>2</b> <i class="fas fa-star text-warning"></i></div>
<div class="progress-label-right">(<span id="total_two_star_review">0</span>)</div>
<div class="progress">
<div class="progress-bar bg-warning" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" id="two_star_progress"></div>
</div>
</p>
<p>
<div class="progress-label-left"><b>1</b> <i class="fas fa-star text-warning"></i></div>
<div class="progress-label-right">(<span id="total_one_star_review">0</span>)</div>
<div class="progress">
<div class="progress-bar bg-warning" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" id="one_star_progress"></div>
</div>
</p>
</div>
</div>
</div>
</div>
<h3 class="mt-3 ml-4">Product Reviews:</h3>
<div class="mt-3" id="review_content">
</div>
</div>
</body>
</html>
<div id="review_modal" class="modal" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Submit Review</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<h4 class="text-center mt-2 mb-4">
<i class="fas fa-star star-light submit_star mr-1" id="submit_star_1" data-rating="1"></i>
<i class="fas fa-star star-light submit_star mr-1" id="submit_star_2" data-rating="2"></i>
<i class="fas fa-star star-light submit_star mr-1" id="submit_star_3" data-rating="3"></i>
<i class="fas fa-star star-light submit_star mr-1" id="submit_star_4" data-rating="4"></i>
<i class="fas fa-star star-light submit_star mr-1" id="submit_star_5" data-rating="5"></i>
</h4>
<div class="form-group">
<label for="">Your Name:</label>
<input type="text" name="user_name" id="user_name" class="form-control" placeholder="Enter Your Name" />
</div>
<div class="form-group">
<label for="">Comment:</label>
<textarea name="user_review" id="user_review" class="form-control" placeholder="Type Review Here"></textarea>
</div>
<div class="form-group text-center mt-4">
<button type="button" class="btn btn-primary" id="save_review">Submit</button>
</div>
</div>
</div>
</div>
</div>
<script>
$(document).ready(function() {
var rating_data = 0;
$('#add_review').click(function() {
$('#review_modal').modal('show');
});
$(document).on('mouseenter', '.submit_star', function() {
var rating = $(this).data('rating');
reset_background();
for (var count = 1; count <= rating; count++) {
$('#submit_star_' + count).addClass('text-warning');
}
});
function reset_background() {
for (var count = 1; count <= 5; count++) {
$('#submit_star_' + count).addClass('star-light');
$('#submit_star_' + count).removeClass('text-warning');
}
}
$(document).on('mouseleave', '.submit_star', function() {
reset_background();
for (var count = 1; count <= rating_data; count++) {
$('#submit_star_' + count).removeClass('star-light');
$('#submit_star_' + count).addClass('text-warning');
}
});
$(document).on('click', '.submit_star', function() {
rating_data = $(this).data('rating');
});
$('#save_review').click(function() {
var user_name = $('#user_name').val();
var user_review = $('#user_review').val();
if (user_name == '' || user_review == '') {
alert("Please Fill Both Field");
return false;
} else {
$.ajax({
url: "submit_rating.php",
method: "POST",
data: {
rating_data: rating_data,
user_name: user_name,
user_review: user_review
},
success: function(data) {
$('#review_modal').modal('hide');
load_rating_data();
alert(data);
}
})
}
});
load_rating_data();
function load_rating_data() {
$.ajax({
url: "submit_rating.php",
method: "POST",
data: {
action: 'load_data'
},
dataType: "JSON",
success: function(data) {
$('#average_rating').text(data.average_rating);
$('#total_review').text(data.total_review);
var count_star = 0;
$('.main_star').each(function() {
count_star++;
if (Math.ceil(data.average_rating) >= count_star) {
$(this).addClass('text-warning');
$(this).addClass('star-light');
}
});
$('#total_five_star_review').text(data.five_star_review);
$('#total_four_star_review').text(data.four_star_review);
$('#total_three_star_review').text(data.three_star_review);
$('#total_two_star_review').text(data.two_star_review);
$('#total_one_star_review').text(data.one_star_review);
$('#five_star_progress').css('width', (data.five_star_review / data.total_review) * 100 + '%');
$('#four_star_progress').css('width', (data.four_star_review / data.total_review) * 100 + '%');
$('#three_star_progress').css('width', (data.three_star_review / data.total_review) * 100 + '%');
$('#two_star_progress').css('width', (data.two_star_review / data.total_review) * 100 + '%');
$('#one_star_progress').css('width', (data.one_star_review / data.total_review) * 100 + '%');
if (data.review_data.length > 0) {
var html = '';
for (var count = 0; count < data.review_data.length; count++) {
html += '<div class="row mb-3">';
html += '<div class="col-sm-1"><div class="rounded-circle bg-danger text-white pt-2 pb-2"><h3 class="text-center">' + data.review_data[count].user_name.charAt(0) + '</h3></div></div>';
html += '<div class="col-sm-11">';
html += '<div class="card">';
html += '<div class="card-header"><b>' + data.review_data[count].user_name + '</b></div>';
html += '<div class="card-body">';
for (var star = 1; star <= 5; star++) {
var class_name = '';
if (data.review_data[count].rating >= star) {
class_name = 'text-warning';
} else {
class_name = 'star-light';
}
html += '<i class="fas fa-star ' + class_name + ' mr-1"></i>';
}
html += '<br />';
html += data.review_data[count].user_review;
html += '</div>';
html += '<div class="card-footer text-right">On ' + data.review_data[count].datetime + '</div>';
html += '</div>';
html += '</div>';
html += '</div>';
}
$('#review_content').html(html);
}
}
})
}
});
</script>