我正在嘗試制作一個結果管理系統,我從 Mysql 資料庫中獲取學生姓名,并且每個學生都有一個唯一的 ID。我想將它呈現為有行和列的表格。我也完成了,但是我如何使用 $_POST 并將其保存在 Mysqli 中,因為有 100 值。我做的是:
php
while ($student_row = mysqli_fetch_assoc($res){
<input type = "number" name = "mark1-<?php echo $student_row['roll']">
}
我已經完成了,現在我通過 $_POST 獲取所有值,但是很難定義每個變數然后將其提交到 MySql 表。
如果我可以使用任何圖書館,請告訴我。
喜歡給定的影像:

uj5u.com熱心網友回復:
這可能會有所幫助,即使問題不是很清楚(對我來說),但如果你這樣寫你的輸入名稱:
<input name="students[id_of_the_student][ppt]"/>
<input name="students[id_of_the_student][ma]"/>
<input name="students[id_of_the_student][nb]"/>...
你會在你的帖子變數中有這個:
var_dump($_POST["students"]);
/*
array(1) { // quantity of students in table
[id_of_student]=> array(2)//number of inputs
{
[ppt] = "PPT value",
[ma] => "MA value"
}
}
*/
編輯:這就是你的表格/表格的樣子:
<form id="form-students" method="POST" >
<table>
<thead>
<th>PPT</th>
<th>MA</th>
<th>MB</th>
<!-- And so on... -->
</thead>
<tbody>
<?php while($student_row = mysqli_fetch_assoc($res)) : ?>
<tr>
<?php foreach ($student_row as $key => $value) : ?>
<td><input type="text" name="students[<?= $student_row['id'] ?>][<?= $key ?>]" value="<?= $value ?>"></td>
<?php endforeach ?>
</tr>
<?php endwhile;?>
</tbody>
</table>
</form>
<?php
$students = $_POST['students'];
?>
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/453548.html
上一篇:如何使表單元素的邊框半徑變圓?
