for循环不在foreach循环中执行


the for loop is not executing inside a foreach loop?

我一直在尝试从表格名称中获取所有内容所以一切正常但这里有像question1,question2,question3直到20这样的列所以我也想获取这些内容为此我在foreach循环中使用了for循环foreach循环运行得很好但是for循环不起作用如果你们可以的话请看看我的代码:

<?php
$query = mysqli_query($mysqli,"SELECT * FROM forms") or die(mysqli_connect_error());
$resultset = array();
while ($rows = mysqli_fetch_array($query)) {
    $resultset[] = $rows;
}
$form_questions_no = $resultset['form_questions_no'];
?>
<table>
<thead>
<tr>
<th>Form Name</th>
<th>Form Questions No</th>
<th>Form Questions</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php foreach ($resultset as $result) { ?>
<tr>
<td><?php echo $result['form_name']; ?></td>
<td><?php echo $result['form_questions_no']; ?></td>
<td><?php for($i=0;$i<$form_questions_no;$i++) { $i_query = $i+1; echo "<p>".$result['question'.$i_query]."</p>"; } ?>
</td>
<td>
<form method="post" action="delete_client_query.php">
<button type="submit" name="delusername" class="btn btn-primary" value="<?php echo $result['Username'] ?>">Delete</button></form></td>
</tr>
<?php } ?>
</tbody>
</table>

所以如果你的人可以看看我的代码,请…!请让我知道我做错了什么,这样我就会非常友好…!

因为在你的循环for($i=0;$i<$form_questions_no;$i++)中变量

$form_questions_no

没有定义,实际上是

$result['form_questions_no']

所以你的循环从0到0,也就是0次:)

编辑后

你的变量仍然有错误的值,这个答案仍然解释了你的问题。你的变量定义是

$form_questions_no = $result['form_questions_no'];

但是在你的代码中没有$result这样的东西,根据你的代码,$result是:$query