Forum Moderators: coopster

Message Too Old, No Replies

How to get the ID of all the checked boxes on displayed data base QUIC

I want someone to be able to select the questions they want and then displ

         

dino8623

1:22 pm on Oct 27, 2014 (gmt 0)

10+ Year Member



I have displayed a table of my data from the data base with check boxes to the left. I want to find a way to link the check boxes to the question number (ID). when I hit submit I want the selected id's to be echoed. pretty much I want someone to be able to select the questions they want and then display them.

<?php
//maketest.php
$con=mysqli_connect("####","####","#####","###");

$result = mysqli_query($con,"SELECT id,question,choiceA,choiceB,choiceC,choiceD,answer FROM q_and_a ");

echo "<table border='1'>
<tr>
<th>Add</th>
<th>#</th>
<th>Question</th>
<th>A</th>
<th>B</th>
<th>C</th>
<th>D</th>
<th>Answer</th>

</tr>";

while($row = mysqli_fetch_array($result))
{
echo "<tr>";

echo '<td><input type="checkbox" name="questions[]" value="$id"></td>';

echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['question'] . "</td>";
echo "<td>" . $row['choiceA'] . "</td>";
echo "<td>" . $row['choiceB'] . "</td>";
echo "<td>" . $row['choiceC'] . "</td>";
echo "<td>" . $row['choiceD'] . "</td>";
echo "<td>" . $row['answer'] . "</td>";
echo "</tr>";
}
echo "</table>";

mysqli_close($con);

?>

<form method="POST" action="makeTest.php">
<input type="submit" name="make" value="Make Test">
</form>

dino8623

1:26 pm on Oct 27, 2014 (gmt 0)

10+ Year Member



the db shows multiple choice questions with their answers and i want to be able to pick which ones i want to make a test using check boxes.

penders

2:00 pm on Oct 28, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



...a way to link the check boxes to the question number (ID)


You seem to already be doing this - at least in theory - except you have a couple of runtime errors in your code that will prevent this from working...

echo '<td><input type="checkbox" name="questions[]" value="$id"></td>';


In the above code (a single quoted string) $id will appear as a literal string, since no variable parsing or string concatenation is used. But also $id is not defined anyway - I assume this should be $row['id']?

So, this should be something like:

echo '<td><input type="checkbox" name="questions[]" value="'.$row['id'].'"></td>';