Jump to content

Help with checkboxes in tables


joshmaun

Recommended Posts

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>

 

Link to comment
https://forums.phpfreaks.com/topic/186911-help-with-checkboxes-in-tables/
Share on other sites

I'm not completely sure what the problem is, but one thing that should/might solve the weird positing of the submit button and possiably the spacing in the Deathknight column is the fact that

<form action="welcome.php" method="post">

is being echoed with every result. Try moving that higher in your script above the loops and it could solve your problem.

 

also for posting php code you can put it in [-php-] [-/-php-] tags (without the dashes) and it will make it look nicer  :)

Archived

This topic is now archived and is closed to further replies.

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