xxreenaxx1 Posted February 8, 2011 Share Posted February 8, 2011 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 More sharing options...
balance85 Posted February 8, 2011 Share Posted February 8, 2011 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 https://forums.phpfreaks.com/topic/227055-how-to-do-checkbox-instead-of-table/#findComment-1171499 Share on other sites More sharing options...
Psycho Posted February 8, 2011 Share Posted February 8, 2011 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 https://forums.phpfreaks.com/topic/227055-how-to-do-checkbox-instead-of-table/#findComment-1171525 Share on other sites More sharing options...
xxreenaxx1 Posted February 9, 2011 Author Share Posted February 9, 2011 checkbox works. Now can I add these chosen checkbox on to mysql. Eg: if someone choose choice1 and I would like to save this onto answer1 on to my mysql if I confused you then I apologies. Link to comment https://forums.phpfreaks.com/topic/227055-how-to-do-checkbox-instead-of-table/#findComment-1171716 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.