mercredi 30 septembre 2015

How to compare two products using checkbox and button?

Code below add checkboxes and buttons to all products listed from database.

How can I compare two products when two checkboxes must be checked and then button should be clickable(button is disabled when none product is checked) and redirect to another page and show these two products with their specifications?

This must be probably done with some query on usporedi.php page, but the problem are checkboxes and button. When button isn't disabled it redirects to usporedi.php.

I've tried with some scripts, but they didn't work.

I appreciate any help.

<?php
                    
                    $per_page = 10;
                   
                    if (!isset($_GET['page'])) {
                        $page = 1;
                    } else {
                        $page = $_GET['page'];
                    }

                    
                    if ($page <= 1) {
                        $start = 0;
                    } else {
                        $start = $page * $per_page - $per_page;
                    }

                   
                    $query = "SELECT *, FORMAT(cijena,2,'de_DE') FROM artikli WHERE kategorija='laptop'";

                   
                    $num_rows = mysqli_num_rows(mysqli_query($con, $query));

                   
                    $num_pages = ceil($num_rows / $per_page);

                   
                    $query .= " LIMIT $start, $per_page";

                  
                    $result = mysqli_query($con, $query);
                    while ($row = mysqli_fetch_array($result)) {

                        $id = $row ['id'];

                        print
                                "<div id='proizvod'></br><a style='text-decoration:none; color:black;' class='two' href='proizvod.php?id=$id' >" . $row["naziv"] . "" .
                                "<p><img src=" . $row["slika"] . " width='200px' height='200px' style='border-radius: 15px;'></p>" .
                                "<p> Cijena za gotovinu: " . $row["FORMAT(cijena,2,'de_DE')"] . " KN </p>" .
                                "<pre id='pre1'>" . $row["opis"] . "</pre>" .
                                "</a>

**<input type='checkbox' name='Usporedi'>
<button onclick='usporedi()' name='Usporedi' disabled>Usporedi</button>

                    <script>
                    function usporedi(){
                       window.location='usporedi.php';
                    }
                    
                    </script>**
</div>";
                    }
                    ?>



Aucun commentaire:

Enregistrer un commentaire