Php 如何为从SQL生成的表中添加的每一行生成不同的颜色线?
由于代码生成的每一行都是相同的颜色,如何使它每隔一行添加一个稍微深一点的阴影 i、 e: 白色 米色 白色 米色 白色 米色 使其成为一种更具可读性的格式 代码如下:Php 如何为从SQL生成的表中添加的每一行生成不同的颜色线?,php,html,sql,whmcs,Php,Html,Sql,Whmcs,由于代码生成的每一行都是相同的颜色,如何使它每隔一行添加一个稍微深一点的阴影 i、 e: 白色 米色 白色 米色 白色 米色 使其成为一种更具可读性的格式 代码如下: if(mysql_num_rows($result) > 0){ while($row = mysql_fetch_array($result)){ $invoiceitemssql = mysql_query('SELECT * FROM tblinvoiceitems WHERE invoicei
if(mysql_num_rows($result) > 0){
while($row = mysql_fetch_array($result)){
$invoiceitemssql = mysql_query('SELECT * FROM tblinvoiceitems WHERE invoiceid = '.$row['id'].' LIMIT 0,1');
$invoiceitems = mysql_fetch_array($invoiceitemssql);
$html .= '<tr>
<td><a href="invoices.php?action=edit&id='.$row['id'].'">'.$row['id'].'</a></td>
<td>'.$row['firstname'].'</td>
<td>'.$row['lastname'].'</td>
<td>'.$row['companyname'].'</td>
<td>'.$row['city'].'</td>
<td>'.$row['phonenumber'].'</td>
<td>'.$row['date'].'</td>
<td>'.$row['duedate'].'</td>
<td>'.$row['total'].'</td>
<td>'.$invoiceitems['description'].'</td>
</tr>';
}
}
if(mysql\u num\u行($result)>0){
while($row=mysql\u fetch\u数组($result)){
$invoiceitemssql=mysql_查询('SELECT*FROM tblinvoiceitems,其中invoiceid='.$row['id'.'LIMIT 0,1');
$invoiceitems=mysql\u fetch\u数组($invoiceitemssql);
$html.='
“.$row['firstname']”
“.$row['lastname']”
“.$row['companyname']”
“.$行[“城市]。”
“.$row['phonenumber']”
“.$row['date']”
“.$row['duedate']”
“.$row['total']”
“.$invoiceitems['description']”
';
}
}
像这样
$i = 0;
if(mysql_num_rows($result) > 0){
while($row = mysql_fetch_array($result)){
if ($i % 2 == 0) {
color white
} else {
color beige
}
$i++;
}
}
你可以使用css
tr:nth-child(even) {background: #CCC}
tr:nth-child(odd) {background: #FFF}
使用计数器切换背景颜色:
$i=0;
while($row = mysql_fetch_array($result)){
if($i%2 == 0)
$bgcolor='beige'; // change the color code as needed
else
$bgcolor='white';
$i++;
......
$html .= '<tr style="background:#'.$bcolor.'">
$i=0;
while($row=mysql\u fetch\u数组($result)){
如果($i%2==0)
$bgcolor='米色';//根据需要更改颜色代码
其他的
$bgcolor='white';
$i++;
......
$html.='
您可以使用CSS来实现这一点,这样您就不必使用凌乱的php循环来添加颜色
HTML
您可以使用CSS为每个不同的行设置样式 例如:
tr:nth-child(odd)
{
background:#fff;
}
tr:nth-child(even)
{
background:#ddd;
}
这是一个。很容易理解的可能的副本,我不是一个程序员,谢谢你的帮助。
table tr:nth-child(odd) {
background:#F00;
}
table tr:nth-child(even) {
background:#FF0;
}
tr:nth-child(odd)
{
background:#fff;
}
tr:nth-child(even)
{
background:#ddd;
}