简体   繁体   English

按ID对表元素的值分组

[英]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. 现在,在mysql db中,每个参赛者都有一个ID,我要做的是当某人更改玩家的得分并单击提交时,可以通过ID关联哪个玩家提交了。 This is organized in an html table and i have no clue how to group the data. 这是在html表中组织的,我不知道如何对数据进行分组。 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. 我需要的是一种方法来告诉javascript,随着玩家指向保存,它应该处理哪个输入字段。 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. 使用“ player1_points”,“ player2_points”等值命名您的表单字段。在服务器上,遍历接收到的所有值,寻找这些字段。 Welcome to 1993. 欢迎来到1993。

EDIT: get thyself a toolkit, like extjs, which handles all this nonsense (and much more) automatically. 编辑:自己获得一个工具包,例如extjs,它可以自动处理所有这些废话(还有更多)。 ext4js is a huge improvement over previous versions. ext4js是对先前版本的巨大改进。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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