所以我已经做了一些研究,但我找不到一个非常有效的解决方案(可能是因为我缺乏PHP经验)。我所拥有的是一个表格中的html表格,我可以使用Javascript动态添加行,所以当我提交表单时,我希望能够处理未知数量的数据。这就是我的表格看起来像
Query query = new Query();
query.addCriteria(Criteria.where("listVouchers.id").is("1234"));
List<Host> host = mongoTemplate.find(query, Host.class);
我添加行的功能会复制每个选择框的名称,因为它们是一个数组,我希望当它们被处理后我可以在getCreditReport.php中执行类似的操作...
<form action = "getCreditReport.php" method = "post">
<tbody>
<tr id='addr0' data-id="0" class="hidden">
<td data-name="courseDropdown[]">
<select name="courseDropdown[]">
<option value = "">Select Course</option>
<?php
$dbconn = pg_connect("host=localhost dbname=ourDB user=postgres password=*******")
or die('Could not connect: ' . pg_last_error());
$stat = pg_connection_status($dbconn);
if ($stat === PGSQL_CONNECTION_OK) {
echo 'Connection status ok';
} else {
echo 'Connection status bad';
}
$result = pg_query($dbconn, "SELECT id, title FROM courses");
while ($row = pg_fetch_row($result)) {
echo "<option value=".$row[0].">".$row[1]."</option>";
}
pg_close($db);
header('Content-type: application/json');
echo json_encode($result);
?>
<td data-name="yearDropdown[]">
<select name="yearDropdown[]">
<option value = "">Select Year Taken</option>
<option value = "2015">2015</option>
<option value = "2014">2014</option>
<option value = "2013">2013</option>
<option value = "2012">2012</option>
<option value = "2011">2011</option>
<option value = "2010">2010</option>
<option value = "2009">2009</option>
<option value = "2008">2008</option>
</select>
</td>
<td data-name="selterm[]">
<select name="selterm[]">
<option value = "">Select Term</option>
<option value = "1">Spring</option>
<option value = "2">Fall</option>
<option value = "3">Winter</option>
<option value = "4">Summer</option>
</select>
</td>
<td data-name="del">
<button nam"del0" class='btn btn-danger glyphicon glyphicon-remove row-remove'></button>
</td>
</tr>
</tbody>
<input type= "submit" value = "Submit">
</form>
我希望$ _POST ['courseDropdown']是用户在提交之前添加的行中所有选定选项的值的数组,但是当我尝试运行它时,没有任何回显。
同样,对PHP非常缺乏经验,所以请放轻松我,但这可能会发生什么?这是解决方案的好方法吗?如果不是什么可能是更好的方式?提前谢谢!
以下是添加动态行的代码。
<html>
<body>
`<?php
$dbconn = pg_connect("host=localhost dbname=ourDB user=postgres password=*****")
or die('Could not connect: ' . pg_last_error());
// For as many rows as the user submits
for ($i = 0; $i < count($_POST['courseDropdown']); $i++) {
$courseDropdown = $_POST['courseDropdown'][$i]; // Get this course from the array
// Do some PHP Stuff Here, maybe...
echo $courseDropdown;
}
pg_close();
?>
</body>
</html>