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 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私