jeudi 30 mai 2019

multiple checkboxes with paging in php without using javascript and jquery

Good day I have an html table and I use paging on it so that only certain amount of items is shown. The problem is that I need to have a multiple selection with checkboxes and that works for a single page but I need that to work between pages. So for example on page 1 you choose 3 items and in the next page you choose 5 items and when GET happens I need to have all those items in one place so that I can store them in a variable.

<?php
session_start();
?>
<html>
    <body>

    <?php
    include("connect.php");     //database connection file
    $limit = 7;
        if ( isset($_GET['page']) ) {
            $page_no = $_GET['page'];
        } else {
            $page_no = 1;
        }
        $start_from = ($page_no-1)*$limit;
        $sql = "SELECT * FROM emp_info LIMIT $start_from,$limit ";
        $result = mysqli_query($conn , $sql);
    ?>

        <form method="GET" action="project.php?name=<?php echo 
$data['name']; ?>">
            <div class="container">
                <h2>employee information:</h2>
                <table class="table table-striped table-hover">
                    <thead>
                        <tr>
                            <th>EmpId</th>
                            <th>Name</th>
                            <th>Email</th>      
                        </tr>
                    </thead>
                    <tbody>

                    <?php
                    $info = "SELECT * 
                        FROM emp_info LIMIT $start_from,$limit ";           
//query to select the data from database
                    $query = mysqli_query ($conn , $info);
                    while ( $data = mysqli_fetch_assoc ($query) ) 
{       //query to fetch the data
                        $_SESSION['emp_name']=$data['name'];
                        ?>  <tr> 
                            <td><?php echo $data['emp_id'];?></td>
                            <td><a href="project.php?id=<?php echo 
$data['emp_id'];?>&name=<?php echo $data['name']; ?>"> <input 
type="checkbox" name="check_list[]" value="<?php echo 
$data['name'];?>"> </a> <?php echo $data['name'];?></td>  
                            <td><?php echo $data['email'];?></td>           

                        </tr>
                    <?php           }
            ?>
                    </tbody>            
                </table>
                <ul class="pagination"> 
                <?php   
                        $sql = "SELECT COUNT(*) FROM emp_info";   
                        $result = mysqli_query($conn , $sql);   
                        $row = mysqli_fetch_row($result);   
                        $total_records = $row[0];   
                        // Number of pages required. 
                        $total_pages = ceil($total_records / 
$limit);   
                        $pagLink = "";                         
                        for ( $i = 1; $i <= $total_pages; $i++) { 
                            if ( $i == $page_no) { 
                                    $pagLink .= "<p>Pages:</p><li 
class='active'><a href='datatable.php?id=" . $data['emp_id'] . 
"&page=" . $i ."'>". $i ."</a></li>";

                        } else  { 
                            $pagLink .= "<li><a 
href='datatable.php?page=". $i ."'>". $i ."</a></li>";   
                        } 
                    };   
                        echo $pagLink;    
                ?> 
                </ul> 
            </div>
            &nbsp; <button type="submit" formaction="project.php" 
name="select_proj">Select Project</button>
            &nbsp; <button type="submit" 
formaction="addnewproj.php"  name="add_proj">Add New 
Project</button>
        </form>
    </body>
</html>




Aucun commentaire:

Enregistrer un commentaire