0
举表我有一个自举表,我使用select从我的数据库中的值:折叠与选择
<table class="table table-hover table-bordered">
<thead>
<tr>
<th>Studentnamn</th>
<th>Student ID</th>
<th>Registrerade kurser</th>
<th>Betyg</th>
</tr>
</thead>
<tbody>
<?php include 'studentDB.php'; ?>
</tbody>
</table>
我想让我的表崩溃,然后显示inputform凡onclicked行的值可以被更新。我用了下面的代码:
$sql = "SELECT student.studName, grades.studId, grades.courseId, grades.grade FROM student
INNER JOIN grades ON student.studId=grades.studId";
try {
foreach ($pdo->query($sql) as $row) {
echo '<tr data-toggle="collapse" data-target="#collapseUpdate">';
echo '<td>' . $row['studName'] . '</td>';
echo '<td>' . $row['studId'] . '</td>';
echo '<td>' . $row['courseId'] . '</td>';
echo '<td>' . $row['grade'] . '</td>';
echo '</tr>';
echo '<tr>';
echo '<td colspan="6" class="hiddenRow" id="collapseRow"><div class="accordian-body collapse" id="collapseUpdate">
<div class="card card-block">
<form class="form-horizontal" action="update.php" method="post" id="newGrade">
<div class="control-group">
<label class="control-label">Nytt betyg:</label>
<div class="controls">
<p><input id="cbetyg" name="grade" type="text"></p>
<input type="hidden" name="studId" value="'. $row['studId'] .'">
<input type="hidden" name="courseId" value="'. $row['courseId'] .'">
</div>
</div>
<div class="form-actions">
<input type="submit" name="submit" value="Ändra">
</div>
</form>
我现在的问题是,只有第一行崩溃,可以使用更新。当我点击其他行时,第一行崩溃...有人能告诉我我能做什么吗?而且,如果我对所有行进行折叠处理,我的更新是否仍然适用于每一行?
My table looks like this (click here)
谢谢!
它的工作!万分感谢!! :D你是我的救命啊:) –
我记得我的PK是studId和courseId的组合,所以现在该怎么办?由于studId不是唯一的,当单击studId时,只有前一行(具有相同的studId)正在崩溃... –
您可以使用'$ row ['studId']。'_'。$ row ['courseId' ]'而不是'$ row ['studId']''。 – Daniel