nascarjunky Posted February 11, 2007 Share Posted February 11, 2007 I would appreciate any help with this. I have a form which includes checkboxes. The descriptions for the checkboxes are loaded from fields in a database table. This part is working well. Please click www.legendnascar.com/alldrivercheckboxes.php to see the form. What I want to do is display the form with the driver name and the values in separate columns so they appear as a table versus the unorganized way they do now. Please see the partial code below: include("nascarconnect.php"); echo "<html> <head><title>All Drivers</title></head> <body>"; $query = "SELECT * FROM AllDrivers ORDER BY salary DESC"; $result = mysql_query($query) or die ("Couldn't execute query."); echo "<div style='margin-left: .5in'> <p> <p><b>Please Select 15 Drivers From The List Below.</b> <p>Be Sure And Select 15:\n"; /* create form containing checkboxes */ echo "<form action='15manrosterselection.php' method='POST'>\n"; while ($row = mysql_fetch_array($result)) { extract($row); echo "<input type='checkbox' name='driver'value='$drid'>$name $salary"; echo "<br>\n"; } echo "<p><input type='submit' value='Submit 15 Man Roster'> </form>\n"; ?> </div></body></html> I would greatly appreciate any help. Quote Link to comment https://forums.phpfreaks.com/topic/38055-formatting-checkboxes-on-forms/ Share on other sites More sharing options...
ToonMariner Posted February 11, 2007 Share Posted February 11, 2007 OK well its good prectice to give your form inputs a label so lets use that to do your check boxes. change this line echo "<input type='checkbox' name='driver'value='$drid'>$name $salary"; to this echo '<label class="chkbxlbl"><input type="checkbox2 name="driver" value="$drid"><span>' . $name . ' ' . $salary . '</span></label>'; (APOLOGOES for switching single and double quotes but I like to see double quotes in html...) in you css... label.chbxlbl { display: block; width: 100%; } label.span { display: block; width: 90%; text-align: right; } Quote Link to comment https://forums.phpfreaks.com/topic/38055-formatting-checkboxes-on-forms/#findComment-182217 Share on other sites More sharing options...
nascarjunky Posted February 12, 2007 Author Share Posted February 12, 2007 Thanks so very much for the reply to my message. The only part I don't understand is the part at the end that says: in your css. . . Followed by the code. I have never used css and I am not familiar with this. Thanks so much. Quote Link to comment https://forums.phpfreaks.com/topic/38055-formatting-checkboxes-on-forms/#findComment-182361 Share on other sites More sharing options...
ToonMariner Posted February 12, 2007 Share Posted February 12, 2007 ok well if you made the other changes then add that 'cc code' to your page by placing it inside a style tag in teh head section of your html. Quote Link to comment https://forums.phpfreaks.com/topic/38055-formatting-checkboxes-on-forms/#findComment-182376 Share on other sites More sharing options...
nascarjunky Posted February 12, 2007 Author Share Posted February 12, 2007 Thanks again so much. I am still having problems. I am assuming I did something incorrect with the placement of the code. <?php /* Program name: alldrivercheckboxes.php * Description: Program displays a list of * checkboxes from database info for selecting 12 man roster. */ //session_start(); //if (@_SESSION['auth'] != "yes") //{ // header("Location: Login.php"); // exit(); // } include("nascarconnect.php"); echo "<html> <head><title>All Drivers</title> <style> label.chbxlbl { display: block; width: 100%; } label.span { display: block; width: 90%; text-align: right; }</style> </head> <body>"; $query = "SELECT * FROM AllDrivers ORDER BY salary DESC"; $result = mysql_query($query) or die ("Couldn't execute query."); echo "<div style='margin-left: .5in'> <p> <p><b>Please Select 15 Drivers From The List Below.</b> <p>Be Sure And Select 15:\n"; /* create form containing checkboxes */ echo "<form action='15manrosterselection.php' method='POST'>\n"; while ($row = mysql_fetch_array($result)) { extract($row); // echo "<input type='checkbox' name='driver'value='$drid'>$name $salary"; echo'<label class="chkbxlbl"><input type="checkbox2" name="driver" value="$drid"><span>' . $name . ' ' . $salary . '</span></label>'; echo "<br>\n"; } echo "<p><input type='submit' value='Submit 15 Man Roster'> </form>\n"; ?> </div></body></html> Here is the result www.legendnascar.com/alldrivercheckboxes.php Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/38055-formatting-checkboxes-on-forms/#findComment-182402 Share on other sites More sharing options...
ToonMariner Posted February 12, 2007 Share Posted February 12, 2007 OK 1st I made a type-o!!! change 'label.span' to 'label span' The second is your bad - type="checkbox2" no such type so get rid of the 2. the last step will be alter the width of the label.chbxlbl to suit your needs... Oh and value="$drid" needs to be value="' . $drid . '" Oh and label.chbxlbl should be label.chkbxlbl in the style tag... Quote Link to comment https://forums.phpfreaks.com/topic/38055-formatting-checkboxes-on-forms/#findComment-182587 Share on other sites More sharing options...
gterre Posted February 22, 2007 Share Posted February 22, 2007 play with this..... <?php include("nascarconnect.php"); echo "<html><head><title>All Drivers</title></head><body>"; $query = "SELECT * FROM AllDrivers ORDER BY salary DESC"; $result = mysql_query($query) or die ("Couldn't execute query."); ?> <div align=center> <table width=100% cellpadding=0 cellspacing=0 border=0> <tr> <td width=10%></td> <td width=80%> <form action="15manrosterselection.php" method="post"> <fieldset><legend>15 Man Roster</legend> <b>Please Select 15 Drivers From The List Below.<br><br>Be Shure and Select 15:</b> <table width=100% cellpadding=0 cellspacing=0 border=0> <tr bgcolor=f1f1f1> <td width=33%></td> <td width=33%><b>Name</b></td> <td width=33%><b>Salary</b></td> </tr> <?php while ($row = mysql_fetch_array($result)) { echo' <tr> <td width=33%><input type="checkbox" name="driver" value="'.$row['drid'].'"></td> <td width=33%>'.$row['name'].'</td> <td width=33%>'.$row['salary'].'</td> </tr> '; } ?> </table> <br><input type='submit' value='Submit 15 Man Roster'> </fieldset> </form> </td> <td width=10%></td> </tr> </table> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/38055-formatting-checkboxes-on-forms/#findComment-190931 Share on other sites More sharing options...
gterre Posted February 22, 2007 Share Posted February 22, 2007 just a note... the input name for your checkboxes should change so you can isolate the values. example... <input type="checkbox" name="driver1" value="some value"> <input type="checkbox" name="driver2" value="some value"> <input type="checkbox" name="driver3" value="some value"> <input type="checkbox" name="driver4" value="some value"> <input type="checkbox" name="driver5" value="some value"> That way you can have. $value1 = $_POST['driver1']; $value2 = $_POST['driver2']; $value3 = $_POST['driver3']; etc.... Quote Link to comment https://forums.phpfreaks.com/topic/38055-formatting-checkboxes-on-forms/#findComment-190933 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.