include 'db.php'; // int_pop toplam değeri $query_int_pop = "SELECT SUM(int_pop) AS total_pop FROM kelime WHERE int_pop IS NOT NULL"; $stmt_int_pop = $pdo->query($query_int_pop); $total_pop = $stmt_int_pop->fetch(PDO::FETCH_ASSOC)['total_pop']; // Toplam kelime sayısı $query_word_count = "SELECT COUNT(*) AS total_words FROM kelime"; $stmt_word_count = $pdo->query($query_word_count); $total_words = $stmt_word_count->fetch(PDO::FETCH_ASSOC)['total_words']; // Toplam boş veya null char_tur sayısı $query_empty_char_tur = "SELECT COUNT(*) AS empty_char_tur FROM kelime WHERE char_tur IS NULL OR char_tur = ''"; $stmt_empty_char_tur = $pdo->query($query_empty_char_tur); $empty_char_tur = $stmt_empty_char_tur->fetch(PDO::FETCH_ASSOC)['empty_char_tur']; // int_pop değeri en düşük olan kelimeyi çek $query = "SELECT char_eng, char_tur, int_pop FROM kelime WHERE char_tur IS NOT NULL AND int_pop IS NOT NULL ORDER BY int_pop ASC LIMIT 1"; $stmt = $pdo->query($query); $correctWord = $stmt->fetch(PDO::FETCH_ASSOC); if (!$correctWord) { die("Doğru kelime bulunamadı."); } $english_word = $correctWord['char_eng']; $correct_turkish_word = $correctWord['char_tur']; // Yanlış şıkları çekme $query_wrong = "SELECT char_tur, int_pop FROM kelime WHERE char_tur IS NOT NULL AND char_tur != ? ORDER BY RAND() LIMIT 2"; $stmt_wrong = $pdo->prepare($query_wrong); $stmt_wrong->execute([$correct_turkish_word]); $wrongWords = $stmt_wrong->fetchAll(PDO::FETCH_ASSOC); if (count($wrongWords) < 2) { die("Yeterli sayıda yanlış şık bulunamadı."); } $wrong_turkish_word_1 = $wrongWords[0]['char_tur']; $wrong_turkish_word_2 = $wrongWords[1]['char_tur']; // Seçeneklerin karışık sıralanması için diziyi karıştır $options = [$correct_turkish_word, $wrong_turkish_word_1, $wrong_turkish_word_2]; shuffle($options); // Yanlış olan seçeneklerin int_pop değerini artır $query_update_options_pop = "UPDATE kelime SET int_pop = int_pop + 0.1 WHERE char_tur IN (?, ?)"; $stmt_update_options_pop = $pdo->prepare($query_update_options_pop); $stmt_update_options_pop->execute([$wrong_turkish_word_1, $wrong_turkish_word_2]); // Cevap kontrolü ve popülerlik güncelleme if (isset($_GET['correct'])) { if ($_GET['correct'] == 'true') { // Doğru cevap verildiyse int_pop'ı 2 artır $query_update_pop = "UPDATE kelime SET int_pop = int_pop + 2 WHERE char_eng = ?"; } else { // Yanlış cevap verildiyse int_pop'ı 1 azalt $query_update_pop = "UPDATE kelime SET int_pop = int_pop - 1 WHERE char_eng = ?"; } $stmt_update_pop = $pdo->prepare($query_update_pop); $stmt_update_pop->execute([$english_word]); // Yeni soruya geçmek için sayfayı yenileyin header("Location: " . $_SERVER['PHP_SELF']); exit(); } // Yeni kelimeyi tekrar seçmek için en düşük int_pop değerine göre sıralama, NULL olanları göz ardı et $query_next_word = "SELECT char_eng, char_tur, int_pop FROM kelime WHERE char_tur IS NOT NULL AND int_pop IS NOT NULL ORDER BY int_pop ASC LIMIT 1"; $stmt_next_word = $pdo->query($query_next_word); $nextWord = $stmt_next_word->fetch(PDO::FETCH_ASSOC); if (!$nextWord) { die("Yeni kelime bulunamadı."); } $next_english_word = $nextWord['char_eng']; $next_correct_turkish_word = $nextWord['char_tur']; // Yanlış şıkları almak için farklı kelimelerden rastgele 2 tane kelime al, NULL olanları göz ardı et $query_wrong_next = "SELECT char_tur FROM kelime WHERE char_tur IS NOT NULL AND char_tur != ? ORDER BY RAND() LIMIT 2"; $stmt_wrong_next = $pdo->prepare($query_wrong_next); $stmt_wrong_next->execute([$next_correct_turkish_word]); $wrongWordsNext = $stmt_wrong_next->fetchAll(PDO::FETCH_ASSOC); if (count($wrongWordsNext) < 2) { die("Yeni yanlış şıklar bulunamadı."); } $wrong_turkish_word_next_1 = $wrongWordsNext[0]['char_tur']; $wrong_turkish_word_next_2 = $wrongWordsNext[1]['char_tur']; // Yeni seçenekler $options_next = [$next_correct_turkish_word, $wrong_turkish_word_next_1, $wrong_turkish_word_next_2]; shuffle($options_next); Kelime Testi

Kelime Testi

Kelime:

Toplam int_pop Değeri: Veri Yok

Toplam Kelime Sayısı:

Boş char_tur Sayısı: