简体   繁体   中英

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. It is like this...

I got team1, team2 and team3 from tbl_teams output of my code:

team1 vs team3
team2 vs team0
team3 vs team2

Question: how to save this output in tbl_games ? I used PHP echo in displaying the output on tables which made it hard to save it.

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

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

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; ie with all the PHP parts already evaluated and replaced with plain HTML.

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