Live search with ajax checkboxes mysql

0

I'm developing a streaming video / movie website and I'm having trouble filtering multiple searches.

I have checkboxes with all categories and my idea was that when selecting a checkbox, I changed the query and so on, even though several checkboxes were selected.

<?php
while ($gInfo = $genres->fetch(PDO::FETCH_ASSOC)) {
  if($gInfo['visible'] !== "no")
  {?>

    <input type="checkbox" id="<?php echo $gInfo['genreid']; ?>" name="categoria" value="<?php echo $gInfo['genreid']; ?>"> <label for="<?php echo $gInfo['genreid']; ?>"><?php echo $gInfo['genre']; ?></label>

    <?php}
}
?>

Sofaronlyachievethis(whichisjusttosearchforallmovies):

index.php:

<script>$(document).ready(function(e){$("#search").keyup(function(){
        $("#results").show();
        var movie = $(this).val();
        $.ajax({
            type: 'GET',
            url: 'search.php',
            data: 'movie=' + movie,
            success: function(data){
                $("#results").html(data);
            }
        });
    })
});
</script>

search.php:

<?php
if( isset( $_SERVER['HTTP_X_REQUESTED_WITH'] ) && ( $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest' ) )
{

    // Creating function
    function search($text){
    require_once("assets/includes/system/conn.php");

        // Filtering data
        $text = htmlspecialchars($text);

        // Preparing mysql to fetch data
        $get_name = $conn->prepare("SELECT * FROM movies WHERE titleEN LIKE concat('%', :titleEN, '%')");
        $get_name->execute(array(':titleEN' => $text));
        $data = $get_name->fetchAll();

        if($data){
            foreach ($data as $mInfo) {?>


                    <a href="movie.php?title=<?php echo $mInfo['titleEN']; ?>&m=<?php echo $mInfo['imdbID']; ?>" target="_self">
                        <img src="assets/images/poster/<?php echo $mInfo['poster']; ?>.jpg" alt="<?php echo $mInfo['titleEN']; ?>">

                    </a>

            <?php
            }
        } else {
            echo "No records";
        }
    }

    // call the search function with the data sent from Ajax
    search($_GET['movie']);

} else {
    echo "Restricted access";
} 
?>
    
asked by anonymous 16.03.2018 / 19:30

0 answers