【问题标题】:How to set seperate background color for each comment in php/html?如何为 php/html 中的每个评论设置单独的背景颜色?
【发布时间】:2018-08-15 00:08:08
【问题描述】:

我有以下 php 代码:

<?php 
    $dlikes="SELECT Comment FROM module_feedback_comments WHERE 
     module_id='$module_id'"; 
    $result=mysqli_query($conn,$dlikes);
   // output data of each row
   while($row = mysqli_fetch_array($result))
   {
        echo "" . $row["Comment"]. "</br>";
   }

 ?>

上述查询从数据库中获取所有 cmets。现在,我希望前端的每个评论都有一个单独的背景颜色来区分它们。我不知道如何使用上面的循环来编写 html / css。请帮忙。

【问题讨论】:

    标签: php html css database


    【解决方案1】:

    我添加了一个随机颜色选择器和用于使用它的 html\css:

    <?php 
        $dlikes="SELECT Comment FROM module_feedback_comments WHERE 
         module_id='$module_id'"; 
        $result=mysqli_query($conn,$dlikes);
       // output data of each row
       while($row = mysqli_fetch_array($result))
       {
            echo "<p style='background-color: ". randCol() ."'>" . $row["Comment"]. "</p>";
       }
    
        function randCol(){
        return '#' . str_pad(dechex(mt_rand(0, 0xFFFFFF)), 6, '0', STR_PAD_LEFT);
    
        }
    
     ?>
    

    【讨论】:

    • 完美。非常感谢 !!惊人的帮助。高度赞赏。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-07-10
    • 2021-12-17
    • 1970-01-01
    • 2020-05-08
    • 2018-02-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多