<?php require 'ust.php'; ?>
<main id="main" class="main">
  <section class="section dashboard">
    <div class="row">
      <div class="col-12">
        <div class="card">
          <div class="card-body">
            <h5 class="card-title">Haftanın Yorumcuları</h5>
            <?php
            $hygetir = mysqli_fetch_array(mysqli_query($db, "SELECT * FROM site_ayar WHERE id = '1'"));
            $idler = explode (",",$hygetir["haftanin_yid"]);
            $bir = $idler["0"];
            $iki = $idler["1"];
            $uc = $idler["2"];
            $ybilgileri1 = mysqli_fetch_array(mysqli_query($db, "SELECT * FROM yorumcular WHERE id = '$bir'"));
            $ybilgileri2 = mysqli_fetch_array(mysqli_query($db, "SELECT * FROM yorumcular WHERE id = '$iki'"));
            $ybilgileri3 = mysqli_fetch_array(mysqli_query($db, "SELECT * FROM yorumcular WHERE id = '$uc'"));
             ?>
             <p>1. Yorumcu: <?php echo $ybilgileri1["kadi"]; ?></p><br>
             <p>2. Yorumcu: <?php echo $ybilgileri2["kadi"]; ?></p><br>
             <p>3. Yorumcu: <?php echo $ybilgileri3["kadi"]; ?></p><br>
            <form method="post">
              <div class="form-group my-3">
                  <label for="exampleFormControlSelect1"> 1. Yorumcu </label>
                  <select name="1" class="form-control" id="exampleFormControlSelect1">
                    <?php
                    $yorumcugetir = mysqli_query($db, "SELECT * FROM yorumcular");
                    while ($ylistele = mysqli_fetch_array($yorumcugetir)) {?>
                    <option value="<?php echo $ylistele["id"]; ?>"><?php echo $ylistele["kadi"]; ?></option>
                  <?php } ?>
                  </select>
                </div>
                <div class="form-group my-3">
                    <label for="exampleFormControlSelect1"> 2. Yorumcu </label>
                    <select name="2" class="form-control" id="exampleFormControlSelect1">
                      <?php
                      $yorumcugetir = mysqli_query($db, "SELECT * FROM yorumcular");
                      while ($ylistele = mysqli_fetch_array($yorumcugetir)) {?>
                      <option value="<?php echo $ylistele["id"]; ?>"><?php echo $ylistele["kadi"]; ?></option>
                    <?php } ?>
                    </select>
                  </div>
                  <div class="form-group my-3">
                      <label for="exampleFormControlSelect1"> 3. Yorumcu </label>
                      <select name="3" class="form-control" id="exampleFormControlSelect1">
                        <?php
                        $yorumcugetir = mysqli_query($db, "SELECT * FROM yorumcular");
                        while ($ylistele = mysqli_fetch_array($yorumcugetir)) {?>
                        <option value="<?php echo $ylistele["id"]; ?>"><?php echo $ylistele["kadi"]; ?></option>
                      <?php } ?>
                      </select>
                    </div>
                <button name="hyl" type="submit" class="btn btn-primary">Güncelle</button>
              </form>
          </div>
        </div>
      </div>
    </div>
  </section>
</main>
<?php require 'footer.php'; ?>
<?php
if (isset($_POST["hyl"])) {
  $b = $_POST["1"];
  $i = $_POST["2"];
  $u = $_POST["3"];
  $sonuc = $b.",".$i.",".$u;
  $duzenle = mysqli_query($db, "UPDATE site_ayar SET haftanin_yid = '$sonuc' WHERE id = '1'");
  if ($duzenle) {
    echo '<script>swal("Başarılı", "Bilgiler Başarılı Bir Şekilde Düzenlendi", "success");setTimeout(function(){ window.location.assign("haftaniny.php");}, 1500);</script>';
  }else {
    echo '<script>swal("Hata", "Beklenemdik Bir Hata Meydana Geldi Lütfen Tekrar Deneyin.", "error");</script>';
  }
}
 ?>
