Recover data in database by checkbox

Asked

Viewed 119 times

0

Good afternoon

I am having difficulties in recovering the data in the database via checkbox.

<div class="container">
    <div class="row">
        <form action="resultado.php" multiple method="post">
            <h3>Bairros</h3>
            <p><input type="checkbox" name="bairro[]" value="Bairro de Fátima"/>Bairro de Fátima</p>
            <p><input type="checkbox" name="bairro[]" value="Benfica"/>Benfica</p>
            <p><input type="checkbox" name="bairro[]" value="Caju"/>Caju</p>
            <p><input type="checkbox" name="bairro[]" value="Catumbi"/>Catumbi</p>
            <p><input type="checkbox" name="bairro[]" value="Centro"/>Centro</p>

            <input type="hidden" name="acao" value="Enviar"/>
            <input type="submit" value="Enviar"/>
        </form>
        <br>
    </div>
</div>  
  • What exactly is your difficulty? It’s not clear

  • For example, when choosing one or more options in the checkbox, return the value of the boxes that were selected via mysqli in the case of a SELECT * FROM <table>, but associated with what was marked in the checkbox

  • a more or less such query: select * from <table> Where neighborhood='Xyz' and category='Health' and orgao='Municipal'

  • You do it like this. Find out about each function of jquery along with (:checked) it will select the data fields for you.

1 answer

0

$(function(){
$( "#enviar" ).click(function() {



$("input[type=checkbox][name='bairro[]']:checked").each(function(){
    alert($(this).val());
});
  
});

});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container">
<div class="row">

<h3>Bairros</h3>
<p><input type="checkbox" name="bairro[]" value="Bairro de Fátima"/>Bairro de Fátima</p>
<p><input type="checkbox" name="bairro[]" value="Benfica"/>Benfica</p>
<p><input type="checkbox" name="bairro[]" value="Caju"/>Caju</p>
<p><input type="checkbox" name="bairro[]" value="Catumbi"/>Catumbi</p>
<p><input type="checkbox" name="bairro[]" value="Centro"/>Centro</p>

<input type="hidden"  name="acao" value="Enviar"/>
<input type="submit" id="enviar" value="Enviar"/>


</div>
</div>

  • Or you can use post or get to pick up the data using FORM.Now you take this dice play in select and make a comparison using Where ..

Browser other questions tagged

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