2016-12-09 63 views
0

我想在php中創建一個在線attendace,我從學生表中提取學生列表,並且想要將所有chkboxs作爲存在並且如果選中爲不存在,則將其作爲缺席, 我無法做到這一點。插入多行數據到從另一個表中提取的數據庫

<div class="attendance"> 
    <form accept="att.php" method="POST"> 
      <?php 
      $sel_sql = "SELECT * FROM student"; 
      $run_sql = mysqli_query($conn,$sel_sql); 
      while($rows = mysqli_fetch_assoc($run_sql)){ 
       $id = $rows['id']; 
       echo '<input type="checkbox" name="status" value="'.$id.'" checked>'.ucfirst($rows['f_name']).''; 
      } 
     ?> 


     <input type="submit" name="submit_attendance" value="Post Attendance"> 
     <?php echo $msg; ?> 
    </form> 
</div> 

它顯示知府學生名單,但我不知道如何設置插入查詢所有這些chkboxes的

+0

更好地給你的表格樣本結構 –

+0

你真正想要的是什麼還不清楚。但現在首先把如果出席標記爲P,然後只顯示選中其他不顯示檢查。 –

+0

我想從學生表中使用學生名單附加附表。我可以輕鬆地將用戶作爲複選框在頁面上獲取,但我無法將這些學生插入到考勤機中。 – shinzu

回答

0

嘗試此查詢到從另一個表

SELECT * INTO TABLE2 FROM student 

使用where條件上插入學生表作爲where student.column的值來選擇校驗值

+0

你有什麼?請寄給我,會在那裏詳細發送你?那可能嗎? – shinzu

+0

只是在你的問題這裏更新表結構,你可以得到多個答案,並選擇從圖片張貼的最好的 –

+0

。請親切接聽 – shinzu

0

上面用複選框輸入字段

echo '<input type="checkbox" name="status" value="'.$id.'" 'if($row['present_field_of_database']) ? 'checked' : '' 
'>'.ucfirst($rows['f_name']).''; 
+0

傾聽,我有兩個學生在學生表中,我把它們作爲複選框在頁面上檢索。 現在我想要這些複選框附加表,我想插入多行插入查詢。點擊一下 – shinzu

0

它與你的問題,然後精細更新的代碼我希望這是對你的工作

<div class="attendance"> 
     <form accept="att.php" method="POST"> 
       <?php 
        $sel_sql = "SELECT * FROM student"; 
        $run_sql = mysqli_query($conn,$sel_sql); 


        while($rows = mysqli_fetch_assoc($run_sql)){ 
         $id = $rows['id']; 
         // if your $id value is right from $rows['id'] then 
         // change your student table name to the another table where available status of the student 
         $wh_sql = "SELECT * FROM student WHERE id=".$id; 
         $run_wh_sql = mysqli_query($conn, $wh_sql); 
         $Wh_rows = mysqli_fetch_assoc($run_wh_sql); 
         // add student present or absent value to the rows data 
         $rows['status'] = $Wh_rows['status']; 
        } 
         // set value as A or P respectively absent or present add jquery plugins for onclick event while client click on checkbox change value respectively 
         echo '<input type="checkbox" name="status" value="'.$rows['status'].'" 'if($rows['status'] == "A") ?'checked': '' '>'.ucfirst($rows['f_name']).' onclick= "$(this).val(this.checked ? P : A)"'; 
       ?> 

      <input type="submit" name="submit_attendance" value="Post Attendance"> 
      <?php echo $msg; ?> 
     </form> 
    </div> 
+0

先生我沒有任何問題來檢索,我想立刻發佈所有的學生到數據庫。 – shinzu

0
if (isset($_POST['send'])) { 
     $s_id = $_POST['status']; 
     $id = $_POST['student']; 
     if ($s_id) { 
      foreach ($s_id as $s) { 
       foreach ($id as $i) { 
         if (mysqli_query($conn, "INSERT INTO attendence(s_id,status) VALUES('". 
         mysqli_real_escape_string($conn, $s)."','". 
         mysqli_real_escape_string($conn, $i)."')")) { 
          $msg = "success"; 
         }else{ 
          $msg = "failed"; 
         } 
        } 


      } 
     } 
    } 

我有3名學生。當我按發送它發送9個條目。我無法理解如何插入所有學生數據

相關問題