简体   繁体   English

如何从使用php echo显示的html表中的mysql中插入多行

[英]How can I insert multiple rows in mysql from an html table that used php echo for display

I got this code that generates a table and matches teams in a round robin tournament system. 我得到了这段代码,该代码生成一个表格并与循环锦标赛系统中的团队进行匹配。

I retrieved 3 teams on tbl_teams and displayed it on a table that creates games and matches each team to each other. 我在tbl_teams上检索了3个团队,并将其显示在创建游戏并将每个团队彼此匹配的表上。 It is like this... 就是这样

I got team1, team2 and team3 from tbl_teams output of my code: 我从代码的tbl_teams输出中获得了team1,team2和team3:

team1 vs team3
team2 vs team0
team3 vs team2

Question: how to save this output in tbl_games ? 问题:如何在tbl_games保存此输出? I used PHP echo in displaying the output on tables which made it hard to save it. 我使用PHP echo在表上显示输出,这使得保存起来很困难。

Here is my code: 这是我的代码:

<th width="35%">Group 1 Match</th>
        <th></th>
        <th width="35%"></th>
        <th width="15%">Date of Game</th>
        <th width="15%">Time of Game</th>

            <tr><td><b>Round 1</td></b></tr>
            <tr>
                <td> &nbsp <?php echo $x[0]->team_name; ?></td>
                <td>VS</td>
                <td> &nbsp <?php echo $x[2]->team_name; ?></td>
                <td><input type="date" name="date"></td><td><input type="time" name="time"></td>
            </tr>
            <tr><td><b>Round 2</td></b></tr>
            <tr>
                <td> &nbsp <?php echo $x[1]->team_name; ?></td>
                <td>VS</td>
                <td> &nbsp <?php echo $x[0]->team_name; ?></td>
                <td><input type="date" name="date"></td><td><input type="time" name="time"></td>
            </tr>
            <tr><td><b>Round 3</td></b></tr>
            <tr>
                <td> &nbsp <?php echo $x[2]->team_name; ?></td>
                <td>VS</td>
                <td> &nbsp <?php echo $x[1]->team_name; ?></td>
                <td><input type="date" name="date"></td><td><input type="time" name="time"></td>
            </tr>

$x[0] , [1] and [2] contains the result of my query which are the 3 teams $x[0][1][2]包含我的查询结果,这是3个团队

You don't store the entire rendered HTML table in the database, especially because you can't (easily) include PHP code a snippet stored in a database table. 您不会将整个呈现的HTML表存储在数据库中,尤其是因为您不能(轻松地)将PHP代码包括在数据库表中存储的代码段中。 Instead, you store the individual bits of data used to make the table, and re-render the table using PHP code every time you load it from the database. 相反,您存储用于创建表的数据的各个位,并在每次从数据库加载表时使用PHP代码重新呈现该表。

If you do insist of storing the entire rendered HTML table in your database, you have to render it once, and then put the rendered HTML in the DB; 如果您确实坚持将整个呈现的HTML表存储在数据库中,则必须将其呈现一次,然后将呈现的HTML放入数据库中。 ie with all the PHP parts already evaluated and replaced with plain HTML. 即,所有PHP部分均已评估,并替换为纯HTML。

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

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