Jump to content

How to do checkbox instead of table


xxreenaxx1

Recommended Posts

I am retrieving data from mysql and printing this as a table. Now I want to print this as a checkbox. But not sure how to?

 

<?php
mysql_connect("localhost", "root", "")or die("cannot connect");
mysql_select_db("Examination")or die("cannot select DB");

$sql=mysql_query("SELECT * FROM question")
or die(mysql_error());

Print "<table border cellpadding=5>";
while($info = mysql_fetch_array( $sql ))
{
Print "<th>Question:</th> <td>".$info['Que_Question'] . "</td> ";
Print "<th>Choice1:</th> <td>".$info['Que_Choice1'] . "</td> ";
Print "<th>Choice2:</th> <td>".$info['Que_Choice2'] . "</td> ";
Print "<th>Choice3:</th> <td>".$info['Que_Choice3'] . "</td> ";
Print "<th>Choice4:</th> <td>".$info['Que_Choice4'] . "</td> ";



}
Print "</table>";
?>

Link to comment
https://forums.phpfreaks.com/topic/227055-how-to-do-checkbox-instead-of-table/
Share on other sites

echo "<input type=checkbox name=choice1 value=" . $info['Que_Choice1'] . ">";
echo "<input type=checkbox name=choice2 value=" . $info['Que_Choice2'] . ">";
echo "<input type=checkbox name=choice3 value=" . $info['Que_Choice3'] . ">";
echo "<input type=checkbox name=choice4 value=" . $info['Que_Choice4'] . ">";

echo "<input type=checkbox name=choice1 value=" . $info['Que_Choice1'] . ">";
echo "<input type=checkbox name=choice2 value=" . $info['Que_Choice2'] . ">";
echo "<input type=checkbox name=choice3 value=" . $info['Que_Choice3'] . ">";
echo "<input type=checkbox name=choice4 value=" . $info['Que_Choice4'] . ">";

 

Yeah, but checkboxes without labels are pretty worthless. Plus, since that code is run in a loop you would be duplicating fields with the same name. You need to either give the fields unique names or create them as arrays

echo "<input type=\"checkbox\" name=\"choice1[]\" value=\"{$info['Que_Choice1']}\" /> ";
echo "{$info['Que_Choice1']} <br />\n";
echo "<input type=\"checkbox\" name=\"choice2[]\" value=\"{$info['Que_Choice2']}\" /> ";
echo "{$info['Que_Choice2']} <br />\n";
echo "<input type=\"checkbox\" name=\"choice3[]\" value=\"{$info['Que_Choice3']}\" /> ";
echo "{$info['Que_Choice3']} <br />\n";
echo "<input type=\"checkbox\" name=\"choice4[]\" value=\"{$info['Que_Choice4']}\" /> ";
echo "{$info['Que_Choice4']} <br />\n";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.