简体   繁体   中英

Grouping values of table elements by id

I'm making a webpage where one can modify points of players.

Table structure is like this Contestant (text), Points(input text field with default value current player's points), submit

now, in mysql db every contestant has an id, what i want to do is when someone changes a player's points and clicks submit to be able to relate by id which player got submited. This is organized in an html table and i have no clue how to group the data. Anyone can help?

Okay not sure if this is correct, cause i wrote it really fast, but I hope you'll get the idea.

$query = "SELECT `con`.`id`, `av`.`name` as `contestant`, `con`.`points` as `points`
          FROM `contestants` as `con`
          JOIN `mydb`.`avatars` as `av`
          WHERE `con`.`boardId`=$id";

$result = mysql_query($query) or die("ERROR:QUERY_FAILED " . mysql_error()); echo "<h4>Boards List</h4><br/>"; 

$numFields = mysql_num_fields($result);

echo "<table>";
        echo "<tr>";
            for($i = 0; $i < $numFields; $i++)
            {
                if(mysql_field_name($result,$i) != 'id')
                {
                    echo "<th>";
                        echo mysql_field_name($result,$i);
                    echo "</th>";
                }
            } 
        echo "</tr>";

        while($row = mysql_fetch_row($result))
        {
            echo "<tr>";
                for($i = 0; $i < $numFields; $i++)
                {
                    if(mysql_field_name($result, $i) == 'points')
                    {                                       
                        echo "<td><input name='points' type='number' min='0' max='45' value='$row[$i]'></td>";
                    }
                    else 
                    {
                        echo "<td>$row[$i]</td>";
                    }
                }
                echo "<td>
                    <input type='button' value='Save' onclick='SavePlayersData(this)'>
                    </td>";
                echo "</tr>";
        }
echo "</table>";

What I need is a way to tell to javascript which input field it should process as the players points being saved. hope it makes sense. (btw, there will be more fields than just points. This is just an example.

Name your form fields with values like "player1_points", "player2_points", etc. On the server, loop through all values received, looking for these fields. Welcome to 1993.

EDIT: get thyself a toolkit, like extjs, which handles all this nonsense (and much more) automatically. ext4js is a huge improvement over previous versions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM