Php 将多行数据插入从另一个表获取的数据库
我试图在php中创建一个在线Attendac,我从student表中获取学生列表,如果选中,则希望将所有Chkbox作为当前,如果未选中,则作为不存在, 我不能那样做Php 将多行数据插入从另一个表获取的数据库,php,mysqli,Php,Mysqli,我试图在php中创建一个在线Attendac,我从student表中获取学生列表,如果选中,则希望将所有Chkbox作为当前,如果未选中,则作为不存在, 我不能那样做 <div class="attendance"> <form accept="att.php" method="POST"> <?php $sel_sql = "SELECT * FROM student"; $run_
<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>
它显示了完美学生列表,但我不知道如何为所有这些chkboxe设置插入查询
SELECT * INTO TABLE2 FROM student
使用student表上的
where
条件作为where student.column值来选择选中值应用与复选框输入字段相同的内容
echo '<input type="checkbox" name="status" value="'.$id.'" 'if($row['present_field_of_database']) ? 'checked' : ''
'>'.ucfirst($rows['f_name']).'';
echo'.ucfirst($rows['f_name'])”;
我想把这样的条目放在复选框中,如果不选中,它将发布p,如果不选中,它将发布a。我只需要如何一次插入所有sutdent queryt很好,然后用您的问题更新代码,我希望这对您有用
<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>
我有三个学生。当我按send时,它会发送9个条目。我无法理解如何插入所有学生的数据最好给出您的表格示例结构您实际想要什么还不清楚。但现在,首先,如果考勤被标记为P,那么只显示选中的,否则不显示选中的。我想使用student表中的student列表将attandance放到attandance表中。我可以很容易地在页面上以复选框的形式获取用户,但我无法将这些学生插入到考勤tble中。你有什么问题?请寄给我,会寄给你详细的吗?有可能吗?只需更新问题中的表格结构,您就可以得到多个答案,并从图片中选择最佳答案。好心的cehck itlisten,我有两个学生在学生表中,我在页面上以复选框的形式检索他们。现在我想把这些复选框添加到附件表中,我想插入多行的insert查询insert。点击一下,先生,我没有任何问题要检索,我想把所有学生一次发布到数据库中。
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";
}
}
}
}
}