0

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;
}
?>
Anju
  • 502
  • 1
  • 6
  • 20

1 Answers1

0

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

arodriguezdonaire
  • 5,396
  • 1
  • 26
  • 50