开发者

How to display the selected data from this form?

So this is part of my code :

echo "<form name='whatever' action='next.php' method='get'>";

while($row = mysql_fetch_assoc($qsq))
{
echo"<input type='checkbox' name='choice[]' value='" . $row['question_id'] . "' /> ". `$row['question_text'] . '<br />';`

}
echo"<br>";
echo "<input type='submit' value='submit' /></form>";

What should i do in the next.php ? I'm thinking to put the selected info in an 开发者_StackOverflowarray and display it. Then store the selected results in a table.But i am not sure with the codes.I am beginner in php can someone help me with the coding ?Thanks in advance!


First of all I cleaned up your code a little bit. (Using single quoutes around HTML trributes is uncanny).

echo ('<form name="whatever" action="next.php" method="get">');
while ($row = mysql_fetch_assoc ($qsq)) {
   echo ('<input type="checkbox" name="choice[' . $row["question_id"] . ']" value="1" /> ' . $row["question_text"] . '<br />';
}
echo '<br />';
echo '<input type="submit" value="submit" /></form>';

Then you can iterate thru the values with a foreach loop in next.php.

echo ('<ul>');
foreach ($_GET["choice"] as $key => $value){
    echo ('<li>' . $key . ' is ticked</li>');
}
echo ('</ul>');

Note that the array's keys hold the real information here,values wil only contain the number 1.

Take a look ath the source of resulting HTML. This is not theonly possible solution but good for learning purposes.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜