dourang8305 2015-08-10 13:46
浏览 18

在PHP中显示日历上的当前日期数据[重复]

This question already has an answer here:

Hello I want to display current date on current city on current date in calendar. If data is available on that day it will display date and that value else display date and null. I am using this code but can't display.

<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;
}
?>
</div>
  • 写回答

1条回答 默认 最新

  • dougai8673 2015-08-10 13:52
    关注

    Here you have a tutorial which you can use as a reference for finding your error.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。