Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Css 更改通过while循环检索的输出的div格式_Css_Loops - Fatal编程技术网

Css 更改通过while循环检索的输出的div格式

Css 更改通过while循环检索的输出的div格式,css,loops,Css,Loops,我在想,如何在一个循环中更改不同输出的css选项 例如,我从数据库中得到10个结果,我想将前5个输出的颜色更改为红色,并在每个用户名旁边添加一张星星的照片 有什么想法吗 $sql = "SELECT tele_members.Username, tele_members_results_k.Sum, tele_members_results_k.Correct, tele_members_results_k.Incorrect FROM `tele_members` LEFT JOIN

我在想,如何在一个循环中更改不同输出的css选项

例如,我从数据库中得到10个结果,我想将前5个输出的颜色更改为红色,并在每个用户名旁边添加一张星星的照片

有什么想法吗

    $sql = "SELECT tele_members.Username, tele_members_results_k.Sum, tele_members_results_k.Correct, tele_members_results_k.Incorrect FROM `tele_members` LEFT JOIN `tele_members_results_k` ON tele_members.ID = tele_members_results_k.ID WHERE `Correct` - `Incorrect` > '0' ORDER BY `Sum` DESC";
    $query = mysql_query ($sql) or die("Error: " .$mysql_error());

    echo "<table width='639' border='0' cellspacing='0' cellpadding='2'>";
    echo "<tr>";
    echo "<td><b>Логин:</b></td>";
    echo "<td><b>Правильные:</b></td>";
    echo "<td><b>Неправильные:</b></td>";
    echo "<td><b>Активность:</b></td>";
    echo "<td><b>Сумма:</td></b>";
    echo "</tr>";

    while ($row = mysql_fetch_assoc($query)) {
        echo "<tr>";
        for (x=0; x>1; x++) { //I was trying to give the first row name "row1" and change the CSS options for "#row1"
        echo "<div id=row$x>";
        echo "<td>$row[Username]</td>";
        echo "<td>$row[Correct]</td>";
        echo "<td>$row[Incorrect]</td>";
$activity = $row[Correct] - $row[Incorrect]; //I wanted to calculate the number "quantity" of questions using the formula (correct) - (-incorrect)
        echo "<td>$activity</td>";
        echo "<td>$row[Sum]</td>";
        echo "</tr>";
        }
        echo "<td>$row[Username]</td>";
        echo "<td>$row[Correct]</td>";
        echo "<td>$row[Incorrect]</td>";
$activity = $row[Correct] - $row[Incorrect]; //I wanted to calculate the number "quantity" of questions using the formula (correct) - (-incorrect)
        echo "<td>$activity</td>";
        echo "<td>$row[Sum]</td>";
        echo "</tr>";
    }
    echo "</table>";
    }

我希望这能有所帮助

哦,也许像这样?运行代码段或转到

.block\u项目{ 背景:9c0; 宽度:200px; 高度:100px; 边缘底部:10px; 位置:相对位置; } .block\u项目:n-child-n+5{ 背景:455E00; } .block\u项目:n-child-n+5:之前{ 内容:'\2605'; 位置:绝对位置; 右:5px; 顶部:2个; 颜色:fff; 字体大小:22px; } 1区 第2区 第3区 第4区 第5区 6区 第7区 第8区 第9区 布洛克-10
请发布您拥有的代码,并向我们展示您尝试过的内容。@j08691我将更新问题,请检查。它似乎可靠,但在我发布的代码中,我使用for loop为第一个DIV提供了一个id row1。。我需要保留它还是使用CSS我们可以控制哪个div将生效??前五个块不需要任何特定的id,因为使用CSS我们可以捕获它们div:nth-child-n+5{前五个块的样式在这里,你可以更改它的样式,并使用::before psuedo元素添加任何图标}谢谢先生,你让我开心了,这样更简单,我会把它标记为一个答案,因为它正是我想要的。谢谢