When I load the page I want to make a query in the database and check that the result has brought more than 3 results, if I bring it I want it to block a checkbox. How can I do this? I'm using JQuery, PHP, MySQL.
When I load the page I want to make a query in the database and check that the result has brought more than 3 results, if I bring it I want it to block a checkbox. How can I do this? I'm using JQuery, PHP, MySQL.
You can do this in several ways, it will depend on how your page is. For example, you can simply do the query at the top of the page before rendering any HTML and check the condition, if it is true at the time of adding the checkbox you put the disabled attribute.
Another way would be to do an ajax that returns the number of records or even a Boolean value and block the input depending on the result.
Using ajax:
$.get('consulta.php', function(registros) {
if (registros > 3) {
$("#checkbox").attr("disabled", true);
}
});
Using PHP directly at the top of the page:
//não sei como você está acessado o banco ...
$iQtdRegistros = query();
$attr = $iQtdRegistros > 3 ? "disabled='disabled'" : '';
<input type="checkbok" <?php echo $attr; ?> >