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
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'] . ">";

Link to comment
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'] . ">";

 

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";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.