Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/79.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
使用php和html使用多种颜色使表格中的行变得丰富多彩_Php_Html_Css - Fatal编程技术网

使用php和html使用多种颜色使表格中的行变得丰富多彩

使用php和html使用多种颜色使表格中的行变得丰富多彩,php,html,css,Php,Html,Css,下面的代码可以使用两种颜色交替创建带有颜色的表格: $num = mysql_num_rows($qPhysician); $i=0; echo "<table>" while($i < $num) { if ($i % 2 == 0){ echo "<tr class='style1'>"; } else{ echo "<tr class='style2'>"; } echo "<td>" . mysql_result($qPhysici

下面的代码可以使用两种颜色交替创建带有颜色的表格:

$num = mysql_num_rows($qPhysician);
$i=0;
echo "<table>"
while($i < $num)

{
if ($i % 2 == 0){
echo "<tr class='style1'>";
}
else{
echo "<tr class='style2'>";
}
echo "<td>" . mysql_result($qPhysician,$i,"lastName") . "</td>";

echo "<td>" . mysql_result($qPhysician,$i,"firstName") . "</td>";

echo "</tr>";

$i++;

}
echo "</table>";
$num=mysql\u num\u行($qphysican);
$i=0;
回声“”
而($i<$num)
{
如果($i%2==0){
回声“;
}
否则{
回声“;
}
echo“.mysql_结果($QPhysican,$i,“lastName”)”;
echo“.mysql_结果($QPhysican,$i,“firstName”)”;
回声“;
$i++;
}
回声“;

假设我有多种颜色。红、绿、黄、蓝等。有没有办法让桌子交替使用这些颜色?我将如何做到这一点?

您可以使用以下方法来交替每行的颜色(四种颜色)


tr:n第n个孩子(4n+1){
背景:红色;
}
tr:n第n个孩子(4n+2){
背景:绿色;
}
tr:n第n个孩子(4n+3){
背景:黄色;
}
tr:n第n个孩子(4n+4){
背景:蓝色;
}

你好,用户10179141请尝试使用css和html代码

表tr:n子项(2n){
背景色:#4a94ed;
边框颜色:#4a64ed;
}

第1列
第2列
第1列
第2列
第1列
第2列
第1列
第2列

为什么不在
:nth
中使用CSS呢?有一篇关于如何用CSS实现这一点的好文章。请。已在PHP7中删除。了解使用PDO的语句,并考虑使用PDO,Hi @保罗·恩里克,你能给你的答案多加解释吗?4种颜色,而不是两种颜色?保罗Henrique@toti08对不起,我编辑了回复,请再次检查。@user10179141我编辑了回复,再次检查,我只使用了第n个子项(2n)。vai alternando automaticamente
<style> 
tr:nth-child(4n+1) {
    background: red;
}
tr:nth-child(4n+2) {
    background: green;
    }

tr:nth-child(4n+3) {
    background: yellow;
}
tr:nth-child(4n+4) {
    background: blue;
}

</style>