伙计们只是想知道是否有更好的编码风格来从 from 因为我认为我的编码太长并且吃很多行
<body>
<form action="index.php" method="post">
<input type="hidden" name="number_students" value="4">
<table>
<tr>
<td><input type="text" name="name[0]"></td>
<td><input type="text" name="grade[0]"></td>
</tr>
<tr>
<td><input type="text" name="name[1]"></td>
<td><input type="text" name="grade[1]"></td>
</tr>
<tr>
<td><input type="text" name="name[2]"></td>
<td><input type="text" name="grade[2]"></td>
</tr>
<tr>
<td><input type="text" name="name[3]"></td>
<td><input type="text" name="grade[3]"></td>
</tr>
</table>
<input type="submit" name="submit_in" value="submit">
</form>
</body>
php..
$button = $_POST['submit_in'];
$arrayname = array();
$arraygrade = array();
$name= $_POST['name'];
$grade = $_POST['grade'];
$counter2 = 0;
if(isset($button)){
foreach($name as $a => $x){
$arrayname[] ="".$x;
}
foreach($grade as $b => $y){
$arraygrade[] ="".$y;
$counter2+=1;
}
for($v=0;$v<=$counter2-1;$v++){
$insert = "INSERT INTO stud_info(stud_name,stud_grade)
VALUES('$arrayname[$v]','$arraygrade[$v]')";
if(@!mysql_query($insert)){
die('error insert'.mysql_error());
}
}
}
我想知道是否有更简洁的技术来获取这些值,假设输入是动态的,这就是为什么我在名称和 ID 的末尾输入一个数组