gpt4 book ai didi

PHP交替颜色

转载 作者:行者123 更新时间:2023-12-05 08:14:11 25 4
gpt4 key购买 nike

  $dbc = mysql_connect('localhost','root','') or die (mysql_error());  mysql_select_db('payroll') or die (mysql_error()); $sql = "SELECT * FROM employee ORDER BY employee_id DESC";  $result = mysql_query($sql);  while($row = mysql_fetch_array($result)) {  echo "  <tr>  <td style=\"padding-left: 20px; border-bottom: 1px solid #999; border-right: 1px solid #999;\">".$row['first_name']." ".$row['last_name']."</td>  <td style=\"text-align: center; border-bottom: 1px solid #999; border-right: 1px solid #999;  padding-top: 2px ; padding-bottom: 3px ;\"><input type=\"button\" name=\"edit\" value=\"Edit\" class=\"selbtn\">&nbsp;<input type=\"button\" name=\"delete\" value=\"Delete\" class=\"selbtn\"></td>  </tr>  ";  }

我想在循环中添加交替颜色。我应该添加什么代码?

最佳答案

$rowCount = 0;
$colorOne = '#ffffff';
$colorTwo = '#f3f3f3';

while($row = mysql_fetch_array($result)){
$rowColor = ($rowCount % 2) ? $colorOne : $colorTwo;
echo "<element bgcolor='$rowColor'></element>";
$rowCount++;
}

在@Jayrox 评论后编辑。

关于PHP交替颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2941020/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com