我的代码以状态“ to_do”显示列workouts
中的所有数据,但它也重复了模式中的submit_abs
按钮。 This is what happens
单击按钮可以正确更新状态。
<?php # start of first php code
$id = $_GET['id'];
$sql = "SELECT * FROM workouts WHERE w_traineeid = '$id' AND w_status = 'to_do'";
$results = mysqli_query($conn, $sql);
$resultChecks = mysqli_num_rows($results);
if ($resultChecks > 0) {
while ($row = mysqli_fetch_assoc($results)) # end of first php code
{
?>
<a href="php/mgmmsEditWO.php?id=<?php echo $row['w_traineeid']?>" class="btn btn-md" type="submit" id="submit_abs" name="submit_abs" data-toggle="tooltip" title="Confirm" style="background-color:#ecf0f1; color:black " ><span class="glyphicon glyphicon-ok"></span></a>
<?php
}
}
?>
答案 0 :(得分:1)
之所以有多个按钮,是因为您正在循环创建它们。删除while
循环,您将只获得一个按钮:
<?php # start of first php code
$id = $_GET['id'];
$sql = "SELECT * FROM workouts WHERE w_traineeid = '$id' AND w_status = 'to_do'";
/*$sql = "SELECT * FROM workouts";*/
$results = mysqli_query($conn, $sql);
$resultChecks = mysqli_num_rows($results);
if ($resultChecks > 0) { # end of first php code
?>
<a href="php/mgmmsEditWO.php?id=<?php echo $id?>" class="btn btn-md" type="submit" id="submit_abs" name="submit_abs" data-toggle="tooltip" title="Confirm" style="background-color:#ecf0f1; color:black " ><span class="glyphicon glyphicon-ok"></span></a>
<?php
}
?>
您当前正在检查$results
中的行数是否大于0,然后为每行添加一个按钮。