Reputation: 49
I have a column Questions in my table oeQuestions. I want to output each question with a checkbox to the left of it and at the end of them being outputted someone could select which ones they wanted and on submit button the next page will pop up with only the selected questions. I can finally print each question with a checkbox but i need help dynamically changing the values for each as well (my submit button is not shown) any help would be great.
<div style="font-family: kodakku; font-size:25px; font-weight:bold;">
<?php
$sql = " SELECT Question FROM multQuestions ";
$result = mysqli_query($dbCon, $sql);
if(mysqli_num_rows($result)>0)
{
while($row = mysqli_fetch_assoc($result))
{
echo '<input type="checkbox" name="checkboxvar[]" value="Option One">' . $row["Question"]." <br />";
}
}
?>
</div>
Upvotes: 0
Views: 66
Reputation: 319
Digital Chris is correct. You need a way to increment your checkbox ids to uniquely identify them currently they will all have the same value. This becomes especially important if you then want to handle them as individual checkboxes.
Upvotes: 1
Reputation: 6202
What @MarcB was saying in his comment is that you need a unique identifier as the value.
This means you have to add it to your select:
<div style="font-family: kodakku; font-size:25px; font-weight:bold;">
<?php
$sql = " SELECT ID, Question FROM multQuestions ";
$result = mysqli_query($dbCon, $sql);
(Note, I used ID
... you DO have a unique ID on your multQuestions table, right?)
And then use it as the value:
if(mysqli_num_rows($result)>0)
{
while($row = mysqli_fetch_assoc($result))
{
echo '<input type="checkbox" name="checkboxvar[]" value="'.$row["ID"].'">' . $row["Question"]." <br />";
}
}
?>
</div>
Upvotes: 1