vendredi 30 mars 2018

why all of my data is showed even i've put the conditional to show it per 3 data in a slideshow?

this is my code

$produk = $_GET['produk'];
                $sql = "select * from tbproduk where namaproduk = '$produk' ";
                $query = mysqli_query($con,$sql) or die("error $sql");
                $num = mysqli_num_rows($query);
                echo $num;
                if(!empty($num)) {
                    for ($x = 1; $x <= $num / 3; $x++) {
                        echo '<div class="w3-content w3-display-container  mySlides">
                <div class="row">';
                        for ($i = 0; $i <= 5; $i++) {
                            $result = mysqli_fetch_array($query);
                            $namaproduk = $result['namaproduk'];
                            $harga = $result['harga'];
                            $pembeli = $result['pembeli'];
                            if(!empty($harga)) {
                                echo '<div class="col-4">
                             <img class="gbr"/>
                             <span> ' . $harga . ' </span><button class="tengbr" onclick="beli(' . $namaproduk . ',' . $pembeli . ')">Beli</button>
                            </div>';
                            }else{
                                echo "";
                            }
                        }
                        echo '</div>
                        </div>';
                    }
                }else{
                    echo "
                    <script>
                    alert('tidak ada produk yang dimaksud');
                    document.getElementsByClassName('navigasi').style.display = 'none';
                    </script>
                    ";
                }

it's actually worked, but all of my data in variabel $num is showed onload and i have to move to another slideindex and it will be normal. This is my script code

var slideIndex = 1;
showDivs(slideIndex);
function plusDivs(n) {
    showDivs(slideIndex += n);
    document.getElementById('slideindex').innerText = slideIndex;
}

function showDivs(n) {
    var i;
    var x = document.getElementsByClassName("mySlides");
    if (n > x.length) {slideIndex = 1}
    if (n < 1) {slideIndex = x.length}
    for (i = 0; i < x.length; i++) {
        x[i].style.display = "none";
    }
    x[slideIndex-1].style.display = "block";
}

and this is my html code to move to another slide index

<div class="navigasi">
<a style="border: 1px solid black;padding: 10px;background-color: grey;color: white;cursor: pointer;" onclick="plusDivs(-1)">&#10094;</a>
<span id="slideindex"></span>
<a style="border: 1px solid black;padding: 10px;background-color: grey;color: white;cursor:pointer;" onclick="plusDivs(1)">&#10095;</a>

the <span id="slideindex"> is to show where was the index is

Aucun commentaire:

Enregistrer un commentaire