gpt4 book ai didi

php - 更改当天 php css 的背景颜色

转载 作者:行者123 更新时间:2023-11-28 16:31:28 25 4
gpt4 key购买 nike

here is the screenshoot of my result我正在尝试使压延机的代码出现问题。根据我的说法,错误生成的代码是 tablerow.php,我在我认为错误的地方发表了评论。我正在尝试更改当前日期的背景颜色,但不是更改特定单元格的颜色,而是更改了整个月的背景颜色,因此整个 2 月的颜色为绿色。

日历.php

<html>
<?php include 'dbconnect.php' ?>

<head>Event Calander</head>
<body>
<script>
function goLastMonth(month, year){
if(month == 1) {
--year;
month = 13;
}
document.location.href ="<?php $_SERVER['PHP_SELF'];?>?month="+(month-1)+"&year="+year;

}
function goNextMonth(month, year){
if(month == 12) {
++year;
month = 0;
}
document.location.href ="<?php $_SERVER['PHP_SELF'];?>?month="+(month+1)+"&year="+year;

}
</script>
<style>
.today{
background-color: #00ff00;
}
.event{
background-color: #FF8080;
}
</style>

<table border='0'>
<tr>

<td width='50px' colspan='7' align="center">
<?php include 'tableheader.php' ?>
<?php include 'addingData.php' ?>
<?php echo $monthName.", ".$year; ?></td>
</tr>

<tr>
<td width='50px'>Sun</td>
<td width='50px'>Mon</td>
<td width='50px'>Tue</td>
<td width='50px'>Wed</td>
<td width='50px'>Thu</td>
<td width='50px'>Fri</td>
<td width='50px'>Sat</td>
</tr>
<?php include 'tablerow.php' ?>

</table>
<table >
<tr>
<td ><input style='width:50px;' type='button' value='<'name='previousbutton' onclick ="goLastMonth(<?php echo $month.",".$year?>)"></td>
<td width='50px'></td>
<td width='50px'></td>
<td width='50px'></td>
<td width='50px'></td>
<td width='50px'></td>
<td width='50px'><input style='width:50px;' type='button' value='>'name='nextbutton' onclick ="goNextMonth(<?php echo $month.",".$year?>)"></td>
</tr>
</table>
<?php include 'schedule.php' ?>
</body>
</html>

tablerow.php(这是我更改当天颜色的地方)

<?php
echo "<tr>";

$first_day = mktime(0,0,0,$month, 1, $year) ;
$name_of_day = date('w', $first_day) ; //get the day of the weeek
//caluting blank days for the month for diaplay
switch($name_of_day){
case "0": $blank = 0;
break;
case "1": $blank = 1;
break;
case "2": $blank = 2;
break;
case "3": $blank = 3;
break;
case "4": $blank = 4;
break;
case "5": $blank = 5;
break;
case "6": $blank = 6;
break;
}

$total_days = cal_days_in_month(0, $month, $year) ;
$day_count = 1;
while ( $blank > 0 ) {
echo "<td></td>";
$blank = $blank-1;
$day_count++;
}
$day_num = 1;
while ( $day_num <= $total_days )
{
$todaysDate = date("n/j/Y");
$dateToCompare = $month. '/' . $day. '/' . $year;
echo "<td align='center' ";
//this is where i am comparing two dates but it is giving error
//every day of the current month is turnin green
if ($todaysDate == $dateToCompare)
{
echo "class ='today'";

}
echo "> <a href='".$_SERVER['PHP_SELF']."?month=".$month."&day=".$day_num."&year=".$year."&v=true'>".$day_num."</a></td>";

$day_num++;
$day_count++;
//Make sure we start a new row every week
if ($day_count > 7)
{
echo "</tr><tr>";
$day_count = 1;
}
}
while ( $day_count >1 && $day_count <=7 )
{
echo "<td> </td>";
$day_count++;
}


echo "</tr>"


?>

最佳答案

尝试改变这个:

$dateToCompare = $month. '/' . $day. '/' . $year;

进入这个:

$dateToCompare = $month. '/' . $day_num. '/' . $year;

关于php - 更改当天 php css 的背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35254828/

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