有人可以帮我一个循环吗?因为它不起作用
这是我的代码:
$signup = "SELECT * FROM ISPD_signup WHERE ID_user = " .$id;
这是我的表:
如果我从mysqli_fetch_array($alleleden)
中删除它,它只会读出一个注册的成员,如果我离开,它将不会读出任何内容。
$alleleden = mysqli_query($mysqli, $signup);
if (mysqli_num_rows ($alleleden) == 0)
{
echo "<p>Er zijn geen inschrijvingen gevonden! </p>";
}
else
{
echo "<h4>Inschrijvingen: </h4>";
echo "<table>";
echo "<tr>";
echo "<th class='hide'>ID </th>";
echo "<th>Naam </th>";
echo "<th>Beslissing </th>";
echo "</tr>";
while ($lid = mysqli_fetch_array($alleleden));
{
echo "<tr>";
echo "<td class='hide'>" . $lid['ID'] . "</td>";
echo "<td>" . $lid['Naam'] . "</td>";
echo "<td>" . $lid['Beslissing'] . "</td>";
echo "</tr>";
}
echo "</table>";
}
你在while循环中放了一个额外的分号
$alleleden = mysqli_query($mysqli, $signup);
if (mysqli_num_rows ($alleleden) == 0)
{
echo "<p>Er zijn geen inschrijvingen gevonden! </p>";
}
else
{
echo "<h4>Inschrijvingen: </h4>";
echo "<table>";
echo "<tr>";
echo "<th class='hide'>ID </th>";
echo "<th>Naam </th>";
echo "<th>Beslissing </th>";
echo "</tr>";
while ($lid = mysqli_fetch_array($alleleden))
{
echo "<tr>";
echo "<td class='hide'>" . $lid['ID'] . "</td>";
echo "<td>" . $lid['Naam'] . "</td>";
echo "<td>" . $lid['Beslissing'] . "</td>";
echo "</tr>";
}
echo "</table>";
}
试试这个代码吧。
这里的问题是这个循环结束时的分号
while ($lid = mysqli_fetch_array($alleleden)); // <<< there
你需要删除它
while ($lid = mysqli_fetch_array($alleleden))
因为它是php中有效的(end of)语句字符,所以它不会引发错误。
与在C或Perl中一样,PHP要求在每个语句结尾处以分号结束指令。 PHP代码块的结束标记自动表示分号;你不需要一个分号来终止PHP块的最后一行。块的结束标记将包括紧接着的新行(如果存在)。
另外,您可能想要使用mysqli_fetch_assoc()
而不是mysqli_fetch_array()
。
附注:您可能在此处对sql注入开放,因此要么使用预准备语句,要么使用:
$id = (int)$_GET['id'];
这也将通过立即将其指定为整数来防止注入。