如何打印到屏幕上的 mysql 结果并显示只有一个迭代的列?

标签: html5 MySQL PHP
发布时间: 2016/10/23 1:27:17
注意事项: 本文中文内容可能为机器翻译,如要查看英文原文请点击上面连接.

我道歉的标题,但我不能找出更好的描述︰

我从我的 mysql 选择,它将返回以下内容︰

enter image description here

我然后建设中 PHP 以显示它可以打印表中的表

enter image description here

我的问题是如何可以显示只有 1 事件,不是 3

enter image description here

这里是 php 代码︰

更新︰

    $flag = "";
    while ($row = mysqli_fetch_array($results)) {
        if( $flag != $row['eventName']){

            $flag = $row['eventName'];

        ?>

        <tr>
            <td align="left" style="margin-left:20px;font-weight: bolder ; "><?php echo $flag ?></td>
            <td align="right"
                style="margin-right:10px; font-weight: bolder;margin-left:20px"><?php echo $row['gender'] ?></td>
            <td align="left"><label style="margin-right:10px;margin-left:20px">
                    <?php echo $row['swimmer_name'] ?>
                </label></td>
            <td align="center"><label class="lane" name="lane"
                                      style="text-align: center;margin-left:20px"><?php echo $row['lane'] ?></label>
            </td>
            <td align="center"><input type="text" style="width:70px;text-align: center;margin-left:20px" class="time"
                                      value="<?php echo $row['time'] ?>" data-mask="00:00:00"></td>
            <td align="center"><span style="margin-right:10px; margin-left:20px" class="place">
                   <?php echo $row['place'] ?>
                </span></td>

            <td align="center"><span style="margin-right:10px; font-weight: bolder;margin-left:20px"
                                     class="score"><?php echo $row['score'] ?></span></td>
            <td align="center"><span style="margin-right:10px; font-weight: bolder;margin-left:20px"
                                     class="score2"><?php echo $row['scoreB'] ?></span></td>
            <td align="center"><span style="text-align: center;margin-left:20px" class="place2">
                    <?php echo $row['placeB'] ?></span></td>
            <td align="center"><input type="text" style="width:70px;text-align: center;margin-left:20px" class="time"
                                      value="<?php echo $row['timeB'] ?>" data-mask="00:00:00"></td>

            <td align="center"><label class="lane" name="laneB"
                                      style="text-align: center;margin-left:20px"><?php echo $row['laneB'] ?></label>
            </td>
            <td align="left"><label style="text-align: center;margin-left:20px">
                    <?php echo $row['swimmer_nameB'] ?>
                </label></td>

        </tr>


    <?php
    }
        else
            {

                $flag == '<td  </td>' ;
            }
    }


    ?>
    </tbody>
</table>
</body>
</html>

解决方法 1:

我不是 php 专家;但这可能是一种方式...

$flag = "";
$display = "";
while ($row = mysqli_fetch_array($results)) {
    if( $flag != $row['eventName']){
        $flag = $row['eventName'];
        $display=$flag;
    else
        $display="";
?>
    <tr>
        <td align="left" style="margin-left:20px;font-weight: bolder ; "><?php echo $display?></td>

        <td align="right"
            style="margin-right:10px; font-weight: bolder;margin-left:20px"><?php echo $row['gender'] ?></td>
        <td align="left"><label style="margin-right:10px;margin-left:20px">
                <?php echo $row['swimmer_name'] ?>
            </label></td>
        <td align="center"><label class="lane" name="lane"
                                  style="text-align: center;margin-left:20px"><?php echo $row['lane'] ?></label>
        </td>
        <td align="center"><input type="text" style="width:70px;text-align: center;margin-left:20px" class="time"
                                  value="<?php echo $row['time'] ?>" data-mask="00:00:00"></td>
        <td align="center"><span style="margin-right:10px; margin-left:20px" class="place">
               <?php echo $row['place'] ?>
            </span></td>

        <td align="center"><span style="margin-right:10px; font-weight: bolder;margin-left:20px"
                                 class="score"><?php echo $row['score'] ?></span></td>
        <td align="center"><span style="margin-right:10px; font-weight: bolder;margin-left:20px"
                                 class="score2"><?php echo $row['scoreB'] ?></span></td>
        <td align="center"><span style="text-align: center;margin-left:20px" class="place2">
                <?php echo $row['placeB'] ?></span></td>
        <td align="center"><input type="text" style="width:70px;text-align: center;margin-left:20px" class="time"
                                  value="<?php echo $row['timeB'] ?>" data-mask="00:00:00"></td>

        <td align="center"><label class="lane" name="laneB"
                                  style="text-align: center;margin-left:20px"><?php echo $row['laneB'] ?></label>
        </td>
        <td align="left"><label style="text-align: center;margin-left:20px">
                <?php echo $row['swimmer_nameB'] ?>
            </label></td>

    </tr>


<?php
}
    else
        {

            $flag == '<td  </td>' ;
        }
}


?>
</tbody>
</table>
</body>
</html>
官方微信
官方QQ群
31647020