在php

时间:2015-08-10 13:46:20

标签: php mysql

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

<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;
}
?>

1 个答案:

答案 0 :(得分:0)

您可以使用tutorial作为查找错误的参考。