-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetTestimonial.php
47 lines (47 loc) · 1.63 KB
/
getTestimonial.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
<?php
$conn = new mysqli('e93461-mysql.services.easyname.eu', 'u148201db1', '3JAqFhg', 'u148201db1');
//first
$sql2 = "SELECT max(id) FROM testimonials";
$sql3 = "SELECT min(id) FROM testimonials";
$maxid = array_values(mysqli_fetch_array($conn->query($sql2)))[0];
$minid = array_values(mysqli_fetch_array($conn->query($sql3)))[0];
//second
$a = 0;
$gesamt = 0;
for ($id = $maxid; $id >= $minid; $id--){
$sql = "SELECT * FROM testimonials WHERE testimonials.id = $id";
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
$stars = "";
$gesamt += $row["stars"];
for($i = $row["stars"];$i>0;$i--){
$stars.= "★";
}
$a++;
if($a==$maxid){
$last="last";
}else if($a==1){
$last="first";
}else{
$last = "";
}
echo '
<div class="testi '.$a.'" id="'.$last.'">
<span class="stars">'.$stars.'</span>
<blockquote>
'.$row["testimonial"].'
</blockquote>
<div class="bottom">
<h4>'.$row["user"]. '</h4>
<span class="timestamp">'.$row["time"]. '</span>
</div>
</div>
';
}
}
$average = $gesamt / $a;
$limitDecimals = number_format((float)$average, 1, '.', '');
echo "Average Rating: ".$limitDecimals;
$conn->close();
die();
?>