dpwgzi7987 2015-05-11 15:23
浏览 96
已采纳

在PHP中改变颜色

The following are a couple of code snippets from some very basic PHP. I decided to add alternating row colours to make things a bit clearer. However the problem I have is that whatever I set the colour values to the rows alternate between a dark red and fuchsia background. This happens on both Windows and Linux and I cannot understand why?

$row_count = 1; // track rows
//$colour_odd = "#FFE680";
$colour_odd = "F0FFFF";
//$colour_even = "#FFF2BF";
$colour_even = "00FFFF";

while ($row = mysql_fetch_assoc($result)) {
    $row_colour = (($row_count % 2) == 0) ? colour_even: colour_odd;
    echo '
        <tr bgcolor="' . $row_colour . '">
            <td width="150" align="center">' . $row['FirstName'] . '</td>
            <td align="center"><a href="' . $row['LastName'] . '">' .$row['LastName'] . '</a></td>
         </tr>';
    $row_count++;
}
  • 写回答

3条回答 默认 最新

  • duanhe6799 2015-05-11 15:26
    关注

    Putting my comment to an answer:

    colour_even: colour_odd those are treated as constants. You probably forgot the $ signs.

    Using error reporting would have told you something like "Undefined constant colour_even..." etc.

    Modify it to read as: $colour_even: $colour_odd;

    Add error reporting to the top of your file(s) which will help find errors.

    <?php 
    error_reporting(E_ALL);
    ini_set('display_errors', 1);
    
    // rest of your code
    

    Sidenote: Error reporting should only be done in staging, and never production.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用