index.html <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<input type="checkbox" id="checkbox">
<script>
setInterval(function() {
$.ajax({
url: 'kontrol.php',
type: 'POST',
dataType: 'json',
success: function(response) {
if (response.veri === '1') {
$('#checkbox').prop('checked', true);
} else {
$('#checkbox').prop('checked', false);
}
}
});
}, 2000); // 2 saniyede bir kontrol edilecek...
</script>kontrol.php <?php
// Mysql bağlantısı yapılacak
$host = "localhost";
$db_kullanici = "kullanici_adi";
$db_sifre = "sifre";
$db_ismi = "veritabani_adi";
// Mysql bağlantısını oluştur
$db = new mysqli($host, $db_kullanici, $db_sifre, $db_ismi);
$tablo_adi = "veriler"; // hangi tablodsaysa onu yazın
$alan = "alan" // tablodaki kontrol edilecek alan
if ($db->connect_error) {
die("Bağlantı hatası: " . $db->connect_error);
}
$sql = "SELECT ".$alan." FROM ".$tablo_adi." WHERE id = 1";
$sonuc = $db->query($sql);
if ($sonuc->num_rows > 0) {
$cevap = $sonuc->fetch_assoc();
$veri = $cevap[$alan];
} else {
$veri = '';
}
echo json_encode(array($alan => $veri));
$db->close();
?>
Evet, çalıştı. Teşekkür ederim.