Filter database by checkbox

Asked

Viewed 68 times

2

This displays all the data...

public function getProdutosHome($limit = false){
    if($limit == false){
        $query = "SELECT * FROM `fretes` ORDER BY id_frete DESC";   
    }else{
        $query = "SELECT * FROM `fretes` ORDER BY id_frete DESC LIMIT $limit";
    }
    return self::conn()->query($query);
}

How can I filter using checkbox ? every click filter the database data ?

Thank you and sorry for the question.

inserir a descrição da imagem aqui

  • You will have to do by ajax. Set in each checkbox an onchange by calling the ajax function by picking the selected checkbox.

  • Mor return from ajax, seven the element that will be changed.

  • ok thanks for the tip and it worked. But when I click the checkbox to disable it does not display all the data again. is showing the values that were filtered by checkbox.

  • I have to refresh the page to load all the data again.

  • Running ajax only when checkbox is checked? It has to be when you have change.

  • $(Document). ready(Function() { $("#Road Train"). on('change',Function() { var value = $(this). val(); $. ajax( { url:'fetch.php', type:'POST', data:'request='+value, beforeSend:Function() { $("#content_products"). html("Filtering..."); }, Success:Function(date) { $("#content_products"). html(data); }, }); });

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.