Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //validasi url, jika tidak ada id maka kembalikan ke index
- if (!is_numeric($_GET['id'])) {
- header('location:./');
- }
- //include koneksi
- require_once('./connect.php');
- //ambil data content
- $get = $con->query("SELECT c.id_content AS id_content, judul, isi, AVG(rating) AS rate, gambar FROM tbl_content c LEFT JOIN tbl_rating r ON(c.id_content = r.id_content) WHERE c.id_content = '" . $_GET['id'] . "' GROUP BY c.id_content");
- //cek apakah Content ditemukan, jika tidak maka kembalikan ke index
- if ($get->num_rows < 1) {
- header('location:./');
- }
- //fetch data
- $d = $get->fetch_assoc();
- //buat looping untuk rating
- $star = '';
- for ($i = 1; $i <= 5; $i++) {
- if ($i <= ceil($d['rate'])) {
- //masukkan rating ke variabel $star
- $star .= '<span class="on"><i class="fa fa-star"></i></span>';
- } else {
- //masukkan rating ke variabel $star
- $star .= '<span class="off"><i class="fa fa-star"></i></span>';
- }
- }
- //cek rating yang diberikan user berdasarkan ip user
- $cek = $con->query("SELECT * FROM `tbl_rating` WHERE ipuser = '" . md5($_SERVER['REMOTE_ADDR']) . "' AND id_content = '" . $_GET['id'] . "'");
- if ($cek->num_rows > 0) {
- $cek = $cek->fetch_assoc();
- $c = $cek['rating'];
- }
- ?>
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Detail Content</title>
- <!-- bootstrap css versi 4 -->
- <link rel="stylesheet" href="./css/bootstrap.css">
- <!-- custom css -->
- <style>
- @import url(./fonts/font-awesome/css/font-awesome.css);
- form,
- label {
- margin: 0;
- padding: 0;
- }
- .rating {
- border: none;
- float: left;
- }
- .rating>input {
- display: none;
- }
- .rating>label::before {
- margin: 5px;
- font-size: 1.25em;
- font-family: FontAwesome;
- display: inline-block;
- content: "\f005";
- }
- .rating>label {
- color: #ddd;
- float: right;
- }
- .rating>input:checked~label,
- .rating:not(:checked)>label:hover,
- .rating:not(:checked)>label:hover~label {
- color: #f7d106;
- }
- .rating>input:checked+label:hover,
- .rating>input:checked~label:hover,
- .rating>label:hover~input:checked~label,
- .rating>input:checked~label:hover~label {
- color: #fce873;
- }
- .star {
- float: left;
- padding-right: 20px;
- }
- .star span {
- padding: 3px;
- font-size: 20px;
- }
- .on {
- color: #f7d106
- }
- .off {
- color: #ddd;
- }
- </style>
- </head>
- <body>
- <div class="container">
- <div class="row mt-4">
- <div class="col-md-3">
- <img src="./img/<?php echo $d['gambar']; ?>" width="100%">
- </div>
- <div class="col-md-9">
- <h4><?php echo $d['judul']; ?></h4>
- <div class="star">
- <?php echo $star; ?> (<?php echo ($d['rate'] != '') ? (int)$d['rate'] : 0; ?>/5)
- </div>
- <div class="clearfix"></div>
- <p class="lead"><?php echo $d['isi']; ?></p>
- <a href="./" class="btn btn-secondary">Kembali</a>
- </div>
- </div>
- <div class="row mt-4">
- <h4>Silahkan Berikan penilaian anda</h4>
- </div>
- <div class="row">
- <form id='rating' class="rating">
- <input type="hidden" name="id_content" id="IDContent" value="<?php echo $d['id_content']; ?>">
- <input type="radio" class="rate" id="star5" name="rating" value="5" <?php if (isset($c) && $c == '5') {
- echo 'checked';
- } ?> />
- <label for="star5" title="Sempurna - 5 Bintang"></label>
- <input type="radio" class="rate" id="star4" name="rating" value="4" <?php if (isset($c) && $c == '4') {
- echo 'checked';
- } ?> />
- <label for="star4" title="Sangat Bagus - 4 Bintang"></label>
- <input type="radio" class="rate" id="star3" name="rating" value="3" <?php if (isset($c) && $c == '3') {
- echo 'checked';
- } ?> />
- <label for="star3" title="Bagus - 3 Bintang"></label>
- <input type="radio" class="rate" id="star2" name="rating" value="2" <?php if (isset($c) && $c == '2') {
- echo 'checked';
- } ?> />
- <label for="star2" title="Tidak Buruk - 2 Bintang"></label>
- <input type="radio" class="rate" id="star1" name="rating" value="1" <?php if (isset($c) && $c == '1') {
- echo 'checked';
- } ?> />
- <label for="star1" title="Buruk - 1 Bintang"></label>
- </form>
- </div>
- </div> <!-- end container -->
- <script type="text/javascript" src="./js/jquery-2.1.4.min.js"></script>
- <script type="text/javascript">
- $(document).ready(function() {
- $("#rating .rate").click(function() {
- $.ajax({
- url: "./proses.php",
- method: "POST",
- data: {
- rate: $(this).val(),
- id: $('#IDContent').val()
- },
- success: function(obj) {
- var obj = obj.split('|');
- $('#star' + obj[0]).attr('checked');
- $('#hasil').html('Rating ' + obj[1] + '.0');
- $('.star').html(obj[2]);
- alert("terima kasih atas penilaian anda");
- }
- });
- });
- });
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement