PHP代码中CSS样式的问题

时间:2014-09-28 18:15:44

标签: php html css colors styles

首先,我对PHP很新,所以可能会出现一些noob错误。 反正;

我这里有一个目标,就是制作一张基本上是日历的桌子。然后我希望表格中与当天相对应的单元格有红色文本。就这些。但它不起作用。 这是我的代码:

<table border="1" id="calendar">

        <caption><h1>September</h1></caption>
        <?php



            $currentDate = (int)date("d");
            $currentMonth = (int)date("m");
            $currentMonthL = date("L");
            $columnsInRow = 7;
            $daysInMonth = date("t");

            $currentDay = 1;
                for ($i=0 ; $i < $daysInMonth ; $i++) {
                    ECHO '<tr class="cal">';
                        for ($j=0 ; $j < $columnsInRow && $currentDay <= $daysInMonth ; $j++) {
                            ECHO var_dump($currentDay);
                            ECHO var_dump($currentDate);
                            if(currentDate==currentDay) {
                                ECHO '<div style="height:150%;width:100%text-decoration:none;"><td class="cal"><a href="date_info.php?currentDay=' . $currentDay . '"><h2 style"color:red;">' . $currentDay . '</h2></a></td></div>';
                                $currentDay++;
                            }else{
                                ECHO '<div style="height:150%;width:100%text-decoration:none;"><td class="cal"><a href="date_info.php?currentDay=' . $currentDay . '"><h2 style="color:#554100;">' . $currentDay . '</h2></a></td></div>';
                                $currentDay++;                              
                            }
                        }
                    ECHO '</tr>';
                }           
        ?>

    </table>

这就是它给我的(注意当天不是红色):

enter image description here

提前谢谢

2 个答案:

答案 0 :(得分:-1)

您的代码有两个问题。

第一个在php if子句中,if(currentDate==currentDay)需要更正为{​​{1}}。

css标记中的第二个if($currentDate == $currentDay)必须更正为<h2 style"color:red;">

希望这有帮助

答案 1 :(得分:-1)

实际上很简单。

你实际上并没有比较你的变量。仔细看。

if(currentDate===currentDay) 

应该是

if($currentDate===$currentDay) 

Here's an eval.in illustrating this