View Full Version : Help with checkboxes in tables

01-02-2010, 09:32 AM
Hello everyone, I am new to using PHP, and am in need of a little help if anyone would be so kind.

What I am trying to do is pull data for each record from two fields from a table in a database:

player_name (the name of the player)
player_class (what type of character a player plays; e.g. Deathknight, Warrior, Mage)

for each player, a checkbox is created, so that a user could select which players to view more information about (it will display items and date for "loot" a player has received).

The functionality of the code seems in place. What I am working on is the format of the data. I feel the best way to display the data would be to have vertical columns for each unique value of player_class as headings, followed by the players who belong to that class type.

A Mock-up View

Deathknight Warrior Mage
Player 1 Player 3 Player 5
Player 2 Player 4 Player 6

I am having two problems:
1) The submit button for some reason appears before the last table, instead of after it.
2)There is a weird gap between the first and second listing underneath the "Deathknight" table.

Below is a URL to the webpage, along with the code I have so far (please be kind, I am new and I have not cleaned up my code yet as I am still playing with it to get this to work)

Any help or suggestions is appreciated, Thanks.



$query = "SELECT player_name, player_class FROM player ORDER BY player_class";
$result = mysql_query($query);
$num = mysql_numrows($result);
$f1=mysql_result ($result,$i,player_name);
$f2=mysql_result ($result,$i,player_class);
<table border="0" style="display:inline">
<th><?php echo $f2; ?></th>
while ($i < ($num-1)) {
if ($old_class != $f2) {
$old_class = $f2
<table border="0" style="display:inline">
<th><?php echo $f2; ?></th>
<form action="welcome.php" method="post">
<input type="checkbox" name="players[] " value="<?php echo $f1; ?>" />
<?php echo $f1; ?>
$f1=mysql_result ($result,$i,player_name);
$f2=mysql_result ($result,$i,player_class);
<input type="submit" value="Submit" />

01-02-2010, 09:39 AM
To begin with, add a suitable DOCTYPE (http://www.alistapart.com/articles/doctype/) at the top. I'd recommend
"http://www.w3.org/TR/html4/strict.dtd">. Then validate your page using http://validator.w3.org/ and fix the markup errors, if any.

01-02-2010, 10:01 AM
I followed your advice, and it fixed the first of my 2 main issues, along with exposing a lot of mark up errors. Thanks a bunch for your input.

"Errors found while checking this document as HTML 4.01 Strict!
Result: 152 Errors, 32 warning(s) "

I had no idea about DOCTYPE, but am glad you told me :o

Anybody have an idea about the submit button? (Gonna be going through the above errors which I guess could point me to the problem with the location of the submit button, but I'll take any ideas while I'm working through it)

01-02-2010, 10:14 AM
well my problems are fixed! (for now =P)

I had a lot of mark up errors, mostly not closing tags. I decided to start from the bottom, (since that's around the area where the submit button is), closed the <table> tag, refreshed the page, and now it appears exactly how I want it to!:D

I'll spend tomorrow fixing the markup to proper standards, and doing a control break to change color of text per class.

Thanks again!

01-02-2010, 11:08 AM
FYI, when using an HTML doctype, you shouldn't close your tags like input,meta,link with a self close. Or just switch to an xhtml doctype.

PS: Using tables for making layout is very bad (http://www.hotdesign.com/seybold/). Tables are basically for showing tabular data. Also, have a look at http://www.alistapart.com/articles/prettyaccessibleforms/ to see how to make an accessible form.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum