2017-11-22 7 views
0

を使用して、次の数ページにドロップダウンから属性を保つために、私は、ドロップダウン・ページからこのコードを持っています。(すべてではない)どのようにPHPのmysqlの

<div class="row"> 
<div class="col-lg-12"> 
    <div class="panel panel-default"> 
     <div class="panel-heading"> 
      Sila pilih kategori peperiksaan 
     </div> 
      <div class="panel-body"> 
       <div class="row"> 
        <div class="col-lg-6"> 

         <form name="selection" role="form" method="post" action="index.php?pages=peperiksaan2" enctype="multipart/form-data" onsubmit="return validate_form ();"> 


         <div class="form-group"> 

          <?php 


          $sql = "SELECT tahun_nama FROM tahun"; 

          $result = $con->query($sql); 
          ?> 
          <label for="tahun_nama">TAHUN</label> 
          <select class="form-control" id="tahun_nama" name="tahun_id"> 
           <option value=""<?php if(!isset($_POST['tahun_nama']) || (isset($_POST['tahun_nama']) && empty($_POST['tahun_nama']))) { ?>selected<?php } ?>>Sila pilih tahun</option> 
           <?php 
           while($row = $result->fetch_assoc()) { 

            echo '<option value="'.$row['tahun_nama'].'"'. ((isset($_SESSION['tahun_nama']) && !empty($_SESSION['tahun_nama']) && ($_SESSION['tahun_nama'] == $row['tahun_nama'])) ? 'selected="selected"' : '') .'>'.$row['tahun_nama'].' </option>'; 

           } 
           ?> 
          </select>          
         </div> 

         <div class="form-group"> 
          <?php 
          $sql = "SELECT peperiksaan_nama FROM peperiksaan"; 

          $result = $con->query($sql); 
          ?> 
          <label>PEPERIKSAAN</label> 
          <select class="form-control" id="peperiksaan_nama" name="peperiksaan_id"> 
           <option value=""<?php if(!isset($_POST['peperiksaan_nama']) || (isset($_POST['peperiksaan_nama']) && empty($_POST['peperiksaan_nama']))) { ?>selected<?php } ?>>Sila pilih peperiksaan</option> 
           <?php 
           while($row = $result->fetch_assoc()) { 
           ?> 
           <option value="<?php echo $row['peperiksaan_nama']; ?>" <?php if(isset($_POST['peperiksaan_nama']) && $_POST['peperiksaan_nama'] == $row['peperiksaan_nama']) { ?>selected<?php } ?>><?php echo $row['peperiksaan_nama']; ?></option> 
           <?php } ?> 
          </select> 
         </div> 

         <div class="form-group"> 
          <?php 
          $sql = "SELECT darjah_nama FROM darjah"; 

          $result = $con->query($sql); 
          ?> 
          <label>DARJAH</label> 
          <select class="form-control" id="darjah_nama" name="darjah_id"> 
           <option value=""<?php if(!isset($_POST['darjah_nama']) || (isset($_POST['darjah_nama']) && empty($_POST['darjah_nama']))) { ?>selected<?php } ?>>Sila pilih darjah</option> 
           <?php 
           while($row = $result->fetch_assoc()) { 
           ?> 
           <option value="<?php echo $row['darjah_nama']; ?>" <?php if(isset($_SESSION['darjah_nama']) && $_SESSION['darjah_nama'] == $row['darjah_nama']) { ?>selected<?php } ?>><?php echo $row['darjah_nama']; ?></option> 
           <?php } ?> 

          </select> 
         </div> 

         <div class="form-group"> 
          <?php 


          $result = mysqli_query($con,"SELECT * FROM kelas"); 
          ?> 
          <label>KELAS</label> 
          <select class="form-control" id="kelas_nama" name="kelas_id"> 
           <option value=""<?php if(!isset($_POST['kelas_nama']) || (isset($_POST['kelas_nama']) && empty($_POST['kelas_nama']))) { ?>selected<?php } ?>>Sila pilih kelas</option> 
           <?php 
           while($row = mysqli_fetch_array($result)) { 
             echo " <option value=" . $row['kelas_nama'] . ">" . $row['kelas_nama'] ."</option>"; } ?> 
          </select> 
         </div> 

        <!-- <button style="display: block; margin: 0 auto;" type="submit" name="select" class="btn btn-primary" href="pptt415.php">PAPAR</button--> 

          <!--center><a class="btn btn-primary" href="index.php?pages=newpptt415" role="button">PAPAR</a></center--> 

          <center><button type="submit" class="btn btn-primary">PAPAR</button></center> 

          <!--a class="btn btn-primary" style="display: block; margin: 0 auto;" href="index.php?pages=edit_guru&guru_nama=?php echo $guru_nama ?>" role="button"><span class="glyphicon glyphicon-glyphicon glyphicon-pencil" aria-hidden="true"></span></a--> 



         </form> 
        </div> 

       </div> 

      </div> 

    </div> 

</div> 

と、このページからオプションを選択した後ユーザーが選択したオプションに基づいてファイルをインポートする必要がドロップダウン...(以下、いくつかのコード)

<center><h4 class="page-header">PEPERIKSAAN : <?php 

     $peperiksaan_nama=$_POST["peperiksaan_id"]; 
     echo $peperiksaan_nama ?> <br> 
     MATAPELAJARAN : Matematik <br> 
     KELAS : <?php 
     $kelas_nama=$_POST['kelas_id']; 
     $darjah_nama=$_POST['darjah_id']; 
      echo $darjah_nama; ?> <?php 
      echo $kelas_nama; ?> <br> 
     TAHUN : <?php $tahun_nama=$_POST['tahun_id']; echo $tahun_nama?> 
    </h4></center> 

<center> <form id="import" name="import" method="post" enctype="multipart/form-data"> 
    <input type="file" name="file" /><br /> 
    <input class="btn btn-primary" type="submit" name="submit" value="Import"/> <br><br> 
</form> </center> 

<?php 

if(isset($_POST["submit"])) 
{ 
    $file = $_FILES['file']['tmp_name']; 
    $handle = fopen($file, "r"); 
    $c = 0; 
    while(($filesop = fgetcsv($handle, 1000, ",")) !== false) 
    { 

     $murid_ic = $filesop[0]; 
     $murid_nama = $filesop[1]; 
     $murid_markah = $filesop[2]; 
     $murid_gred = $filesop[3]; 
     $tahun_id = $filesop[4]; 
     $peperiksaan_id = $filesop[5]; 
     $kelas_id = $filesop[6]; 
     $darjah_id = $filesop[7];  


     $query = query("INSERT INTO murid (murid_ic,murid_nama, murid_markah, murid_gred, tahun_id, peperiksaan_id, kelas_id, darjah_id) 

     VALUES ('$murid_ic','$murid_nama','$murid_markah','$murid_gred','$tahun_id','$peperiksaan_id','$kelas_id','$darjah_id')"); 

     $c = $c + 1; 
    } 

     if($query){ 

      redirect("index.php?pages=peperiksaan2&tahun_id=$tahun_id&peperiksaan_id=$peperiksaan_id&darjah_id=$darjah_id&kelas_id=$kelas_id"); 
       echo "You database has imported successfully. You have inserted ". $c ." recoreds"; 
     }else{ 
      echo "Sorry! There is some problem."; 
     } 

} 
?> 


    <table width="100%" class="table table-striped table-bordered table-hover"> 
     <thead> 
       <tr> 
        <th>BIL</th> 
        <th>NAMA</th> 
        <th>NO IC</th> 
        <th><center>MARKAH</center></th> 
        <th><center>GRED</center></th> 
       </tr> 
       </thead> 

     <?php    

      $bil = 0; 

      $SQLSELECT = "SELECT murid.*, peperiksaan.*, tahun.*, darjah.*, kelas.* FROM murid, peperiksaan, tahun, darjah, kelas WHERE murid.peperiksaan_id = peperiksaan.peperiksaan_id AND murid.tahun_id = tahun.tahun_id AND murid.darjah_id = darjah.darjah_id AND murid.kelas_id = kelas.kelas_id" ; 

      $result_set = mysqli_query($con, $SQLSELECT); 

      while($row = mysqli_fetch_array($result_set)) 
      { 
       $bil++; 
      ?> 

       <tr> 
        <td><?php echo $bil; ?></td> 
        <td><?php echo $row['murid_nama']; ?></td> 
        <td><?php echo $row['murid_ic']; ?></td> 
        <td><center><?php echo $row['murid_markah']; ?></center></td> 
        <td><center><?php echo $row['murid_gred']; ?></center></td>  

       </tr> 


      <?php 
      } 
     ?>    



それはちょうど良いです。しかし、ファイルをインポートした後、属性はもはやオプションから値を読み取ることはありません。なぜそれが起こるのですか?インポートボタンは同じページにつながります。

クッキーで

答えて

0

店自分の価値観とあなたが

+0

をしたいときに使用アイデアをありがとう..私はそれに見ていきます。.. – Yun