Php 如何限制获取的结果数量,然后对其进行筛选?

Php 如何限制获取的结果数量,然后对其进行筛选?,php,ajax,Php,Ajax,我最近开始学习ajax,以便使用live filter by复选框。在我决定使用order by id asc limit 0、$rowperpage(其中rowperpage=3)限制从数据库获取的结果之前,这一切都很顺利。将此添加到我的代码中会完全禁用复选框过滤器。我可能做错了什么 下面是我的代码 index.php fetch_data.php database_connection.php 数据库表“career” 任何帮助都将不胜感激:我认为您的查询应该是按id asc limit从

我最近开始学习ajax,以便使用live filter by复选框。在我决定使用order by id asc limit 0、$rowperpage(其中rowperpage=3)限制从数据库获取的结果之前,这一切都很顺利。将此添加到我的代码中会完全禁用复选框过滤器。我可能做错了什么

下面是我的代码

index.php

fetch_data.php

database_connection.php

数据库表“career”


任何帮助都将不胜感激:

我认为您的查询应该是按id asc limit从职业订单中选择*$rowperpage@jdavid05这没什么区别。
<?php

//index.php

include('database_connection.php');

?>

<!DOCTYPE html>
<html lang="en">

<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>Product filter in php</title>

    <script src="js/jquery-1.10.2.min.js"></script>
    <script src="js/jquery-ui.js"></script>
    <script src="js/bootstrap.min.js"></script>
</head>

<body>
    <!-- Page Content -->
                <div class="">
                    <h3>Duration</h3>
                    <?php
                    $query = "
                    SELECT DISTINCT(duration) FROM career
                    ";
                    $statement = $connect->prepare($query);
                    $statement->execute();
                    $result = $statement->fetchAll();
                    foreach($result as $row)
                    {
                    ?>
                    <div class="checkbox">
                        <label><input type="checkbox" class="common_selector duration" value="<?php echo $row['duration']; ?>"  > <?php echo $row['duration']; ?></label>
                    </div>
                    <?php
                    }
                    ?>
                </div>

                <br />
                <div class="filter_data">

                </div>

<style>
#loading
{
    text-align:center;
    background: url('loader.gif') no-repeat center;
    height: 150px;
}
.jobs{
  background: gray;
  margin: 10px;
  padding: 10px;
  width: 200px;
}
</style>

<script>
$(document).ready(function(){

    filter_data();

    function filter_data()
    //this deals with filter checkboxes
    {
        $('.filter_data').html('<div id="loading" style="" ></div>');
        var action = 'fetch_data';
        var duration = get_filter('duration');
        $.ajax({
            url:"fetch_data.php",
            method:"POST",
            data:{action:action, duration:duration},
            success:function(data){
                $('.filter_data').html(data);
            }
        });
    }

    function get_filter(class_name)
    {
        var filter = [];
        $('.'+class_name+':checked').each(function(){
            filter.push($(this).val());
        });
        return filter;
    }

    $('.common_selector').click(function(){
        filter_data();
    });


});
</script>

</body>

</html>
<?php

//fetch_data.php

include('database_connection.php');
$rowperpage = 3;
if(isset($_POST["action"]))
{
//statement limits but disables check box filter
    $query = "
        SELECT * FROM career order by id asc limit 0,$rowperpage
    ";
    if(isset($_POST["duration"]))
    {
        $duration_filter = implode("','", $_POST["duration"]);
        $query .= "
         WHERE duration IN('".$duration_filter."')
        ";
    }

    $statement = $connect->prepare($query);
    $statement->execute();
    $result = $statement->fetchAll();
    $total_row = $statement->rowCount();
    $output = '';
    if($total_row > 0)
    {
        foreach($result as $row)
        {
            $output .= '
            <div class="jobs">
                    Title : '. $row['title'] .' <br />
                    duration : '. $row['duration'] .'

            </div>
            ';
        }
    }
    else
    {
        $output = '<h3>No Data Found</h3>';
    }
    echo $output;
}

?>
<?php

//database_connection.php

$connect = new PDO("mysql:host=localhost;dbname=biit", "root", "");

?>