There are two columns: id & questions, which have five rows. I want to display each row in the input value, with the name attribute as ‘quest’. The input with name attribute ‘ans’ will remain blank for answer. The problem is the loop displays each row five times, printing either each question five times, or only one question five times. I tried declaring a variable $i = 1 and incremented it as $i++ after every second input, but I am unable to fix the problem. Could anyone please help me out with your insight?
<form action="code.php" method="post" class="form-inline">
<?php
$query = "SELECT questions FROM stpaper";
$result = mysqli_query($conn, $query);
$row_count = mysqli_num_rows($result);
while ($row = mysqli_fetch_array($result)) {
?>
<label class="label col-md-3 control-label">Q.1</label>
<input type="text" class="form-control" name="quest" value="<?php echo $row['questions']; ?>" >
<label class="label col-md-3 control-label">Ans.</label>
<input type="text" class="form-control" name="ans" value="">
<label class="label col-md-3 control-label">Q.2</label>
<input type="text" class="form-control" name="quest" value="<?php echo $row['questions']; ?>" >
<label class="label col-md-3 control-label">Ans.</label>
<input type="text" class="form-control" name="ans" value="">
<label class="label col-md-3 control-label">Q.3</label>
<input type="text" class="form-control" name="quest" value="<?php echo $row['questions']; ?>" >
<label class="label col-md-3 control-label">Ans.</label>
<input type="text" class="form-control" name="ans" value="">
<label class="label col-md-3 control-label">Q.4</label>
<input type="text" class="form-control" name="quest" value="<?php echo $row['questions']; ?>" >
<label class="label col-md-3 control-label">Ans.</label>
<input type="text" class="form-control" name="ans" value="">
<label class="label col-md-3 control-label">Q.5</label>
<input type="text" class="form-control" name="quest" value="<?php echo $row['questions']; ?>" >
<label class="label col-md-3 control-label">Ans.</label>
<input type="text" class="form-control" name="ans" value="">
<?php
}
mysqli_close($conn);
?>
<button type="submit" class="btn btn-success mt-4 mx-5" name="submit" id="submit">Submit</button>
</form>