Help with checkboxes within tables format |
Help with checkboxes within tables format |
joshmaun |
Jan 2 2010, 03:29 AM
Post
#1
|
Group: Members Posts: 1 Joined: 2-January 10 Member No.: 10,746 |
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. LINK TO WEBPAGE http://www.joshmaun.com/testpage CODE: $query = "SELECT player_name, player_class FROM player ORDER BY player_class"; $result = mysql_query($query); $num = mysql_numrows($result); $i=0; $f1=mysql_result ($result,$i,player_name); $f2=mysql_result ($result,$i,player_class); $old_class=$f2; ?> <table border="0" style="display:inline"> <th><?php echo $f2; ?></th> <?php while ($i < ($num-1)) { if ($old_class != $f2) { $old_class = $f2 ?> <table border="0" style="display:inline"> <th><?php echo $f2; ?></th> <?php } ?> <tr><td> <form action="welcome.php" method="post"> <input type="checkbox" name="players[] " value="<?php echo $f1; ?>" /> <?php echo $f1; ?> </td></tr> <?php $i++; $f1=mysql_result ($result,$i,player_name); $f2=mysql_result ($result,$i,player_class); } ?> <input type="submit" value="Submit" /> </form> </BODY> </HTML> |
Brian Chandler |
Jan 2 2010, 09:10 AM
Post
#2
|
Jocular coder Group: Members Posts: 2,460 Joined: 31-August 06 Member No.: 43 |
Have you tried the validator on this page? You seem to have a lot of unbracketed <form> elements. You can't do it this way.
Incidentally, using a checkbox _name_ of "players[]" is a common suggestion, but I think it looks awfully naff, needing to include [] in your html page just because of a quirk in the way PHP handles input. I think a neater way is to use a single character to identify the argument type, e.g. 'p' for player, then put the player's ID (code/name) as the following characters. (So e.g. name=pRuki value=x. Then if you want to have a table that updates various attributes of the players, by using a different letter to identify each attribute, a single table can submit all the stuff you need.) Again, if you switch on "short brackets (or whatever it's called)" you can replace <?php echo $f2; ?> by <?=$f2?> But you have to find your own style for writing PHP... Anyway, I think if you use the validator, and straighten out the <table> structure too, you will probably get rid of the funny errors. |
Lo-Fi Version | Time is now: 28th April 2024 - 11:34 AM |