Php 显示具有不同颜色的记录 $result=mysqli_查询($conn,“SELECT*FROM countries”); ?> 国家名单 名称

Php 显示具有不同颜色的记录 $result=mysqli_查询($conn,“SELECT*FROM countries”); ?> 国家名单 名称,php,mysql,Php,Mysql,对不起,如果我问错了问题,我是新来的, 实际上,我已经正确运行了上面的查询并显示了来自sql数据库的记录,我现在想要的是用红色显示5个国家,接下来用蓝色显示5个国家,之后用绿色显示,然后用红色重复。。 有人帮我解释一下逻辑和在哪里使用它。。。 再次感谢和抱歉 试试看: $result = mysqli_query($conn,"SELECT * FROM countries"); ?> <div class="container"> <h2 class="hta

对不起,如果我问错了问题,我是新来的, 实际上,我已经正确运行了上面的查询并显示了来自sql数据库的记录,我现在想要的是用红色显示5个国家,接下来用蓝色显示5个国家,之后用绿色显示,然后用红色重复。。 有人帮我解释一下逻辑和在哪里使用它。。。 再次感谢和抱歉

试试看:

   $result = mysqli_query($conn,"SELECT * FROM countries");
?>
<div class="container">
  <h2 class="htag">Countries List</h2>
<div class="form-row">
    <div class="form-group col-md-12">
    <a href="addstudent.php" <button type="button" class="btn btn-primary btn-lg pull-right ">Add New Country</button> </a>
     </div>
     </div>
  <table class="table">
    <thead>
      <tr>
        <th>Name</th>
        </tr>
        </thead>
        <tbody>
        <?php while($row = mysqli_fetch_array($result)){ ?>
        <tr>
        <td><?php echo $row['name']; ?></td>
      </tr>
      <?php  }?>
    </tbody>
  </table>  

国家名单
名称
根据我所看到的,您正在使用Bootstrap4,然后我添加了引用颜色的类


请测试它是否有效。

您尝试过什么?这应该不会太难。您可以考虑使用的纯CSS解决方案。查看官方文档中的,它可以帮助您编写代码
<?php
   $result = mysqli_query($conn,"SELECT * FROM countries");
   $count = 0;
?>
<div class="container">
  <h2 class="htag">Countries List</h2>
<div class="form-row">
    <div class="form-group col-md-12">
    <a href="addstudent.php" <button type="button" class="btn btn-primary btn-lg pull-right ">Add New Country</button> </a>
     </div>
     </div>
  <table class="table">
    <thead>
      <tr>
        <th>Name</th>
        </tr>
        </thead>
        <tbody>
        <?php while($row = mysqli_fetch_array($result)){ 
            if($count < 5) { $color = 'class="table-danger"'; $count = 0;} else { $color = 'class="table-info"';}
            $count++;
            ?>
            <tr>
                <td <?php echo $color ?> ><?php echo $row['name']; ?></td>
            </tr>
        <?php  }?>
        </tbody>
  </table>