gpt4 book ai didi

php - 在php中显示日历上的当前日期数据

转载 作者:行者123 更新时间:2023-11-29 22:08:27 25 4
gpt4 key购买 nike

您好,我想在日历中的当前日期显示当前城市的当前日期。如果当天有数据可用,它将显示日期和该值,否则显示日期和空值。我正在使用此代码,但无法显示。

<form action="" method="post">
<select name="city">
<?php
$city = mysql_query("SELECT * from add_city ");/**select city from city table**/
while($list = mysql_fetch_assoc($city)){
$city_idd= $list['city_id'];
?>
<option value="<?php echo $list['city_id']; ?>"><?php echo $list['city']; ?></option>
<?php } ?>

</select>
<select name="year">
<?php
$year = mysql_query("SELECT * from year");/**select city from Year table**/

while($lyear = mysql_fetch_assoc($year)){
$lyear2= $lyear['year'];
$idyear= $lyear['id'];

?>

<option value="<?php echo $lyear2; ?>"><?php echo $lyear2; ?></option>
<?php } ?>

</select>
<input type="submit" value="Chart" name="view_chart">
</form>
<?php if(isset($_POST['view_chart']) == "Chart")
{ $dYear= $_POST['year'];
$scityid=$_POST['city'];




?>
<?php
$dDaysOnPage = 37;
$dDay = 1;
?>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tr>
<th><?php echo $dYear; ?></th>
<th>Mo</th>
<th>Tu</th>
<th>We</th>
<th>Th</th>
<th>Fr</th>
<th>Sa</th>
<th>Su</th>
<th>Mo</th>
<th>Tu</th>
<th>We</th>
<th>Th</th>
<th>Fr</th>
<th>Sa</th>
<th>Su</th>
<th>Mo</th>
<th>Tu</th>
<th>We</th>
<th>Th</th>
<th>Fr</th>
<th>Sa</th>
<th>Su</th>
<th>Mo</th>
<th>Tu</th>
<th>We</th>
<th>Th</th>
<th>Fr</th>
<th>Sa</th>
<th>Su</th>
<th>Mo</th>
<th>Tu</th>
<th>We</th>
<th>Th</th>
<th>Fr</th>
<th>Sa</th>
<th>Su</th>
<th>Mo</th>
<th>Tu</th>
</tr>
<?php



function FriendlyDayOfWeek($dayNum) {
// converts the sunday to 7
// This function can be removed in php 5 by - date("N"),
// just remove function calls below and replace by swapping date("w" for date("N"
if ($dayNum == 0){ return 7; } else { return $dayNum; }
}

for ($mC=1;$mC<=12;$mC++) {

$currentDT = mktime(0,0,0,$mC,$dDay,$dYear);
echo "<tr><td class='monthName'><div>".date("F",$currentDT)."</div></td>";
$daysInMonth = date("t",$currentDT);

echo InsertBlankTd(FriendlyDayOfWeek(date("w",$currentDT))-1);


for ($i=1;$i<=$daysInMonth;$i++) {
$exactDT = mktime(0,0,0,$mC,$i,$dYear);

$get=mysql_query("select * from add_value where city_id='$scityid'");/**get data from datatable table**/
while($get_result=mysql_fetch_assoc($get))
{


$ddate = date("Y-m-d", strtotime($get_result['date']));
echo $ddate;

if($ddate == $currentDT)
{
$events = $get_result['value'];
}
}
if ($i==date("d")&&date("m",$currentDT)==date("m")) { $class="currentDay"; } else { $class = ""; }


if($events)
{
echo "<td class='".$class." days day".FriendlyDayOfWeek(date("w",$exactDT))."'>".$i.$events."</td>";

}
else{

echo "<td class='".$class." days day".FriendlyDayOfWeek(date("w",$exactDT))."'>".$i."</td>";
}

}
echo InsertBlankTd($dDaysOnPage - $daysInMonth - FriendlyDayOfWeek(date("w",$currentDT))+1);
echo "</tr>";
}
?>


<?php }
?>



</div>
</div>
<?php
include("config.php");
?>
<?php
function InsertBlankTd($numberOfTdsToAdd) {
for($i=1;$i<=$numberOfTdsToAdd;$i++) {
$tdString .= "<td></td>";
}
return $tdString;
}
?>

最佳答案

这里有一个tutorial您可以将其用作查找错误的引用。

关于php - 在php中显示日历上的当前日期数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31921264/

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