Hi!
So, I have a list of records with a date attached, and a calendar which when I click on a date, lists the records which are shown on that date. When the record is created, every one is listed correctly. But when I create a record, and edit the date after the fact, not every change is forewarded correctly to be displayed in the calendar. I can't figure out why some changes are shown and others are not!
Here is some code, which will hopefully point someone in the right direction to help me fix my code.
Thank you!
Code:
calendar, specific day:
$Day = $_GET['Day'];
$Year = $_GET['Year'];
$Month = $_GET['Month'];
$cal_string = date("Y-m-d", strtotime("$Month $Day $Year"));
$sqlquery = "SELECT id, diwtitle, date_string FROM diw_alpha WHERE date_string = '$cal_string'";
calendar, overview:
<TABLE width="10%" align=left>
<TR>
<TD bgcolor="#000080" valign="top" height="80" width="100"><CENTER><img alt="logo_sm (1K)" src="logo_sm.gif" height="80" width="67"><BR><font face="Tahoma" size=2 color="white"><B>I-DEP DIW Management Tool</B></FONT></CENTER></TD>
</TR>
<TR>
<TD bgcolor="#ccccff" height="260" valign="top"><CENTER><font face="Tahoma" size=2 color="black"><B><a href=damndiw1.php>Create new DIW</A><BR>-----<BR><a href=damndiw3.php>View DIW List</A><BR>-----<BR><a href=diw_admin.html>DIW Admin<BR><BR></A></B></FONT></CENTER></TD>
</TR>
</TABLE>
<?php
//get today's date-time
$today=time();
//get the month to display, if no month to get, display this month
$This_Month=$_GET['Month'];
if ($This_Month=="")
$This_Month=date("F",$today);
//get the year to display, if no year to get, display this year
$This_Year=$_GET['Year'];
if ($This_Year=="")
$This_Year=date("Y",$today);
//set display date to the first day of the selected month and year
$First_Day=strtotime("$This_Month 1 $This_Year");
// the next month is guaranteed to be 3,456,000 seconds (40 days)
// from the first day of the selected month
$Plus_Month=$First_Day+3456000;
// the previous month is guaranteed to be 86,401 seconds (24:00:01 hrs)
// less than the first day of the selected month
$Minus_Month=$First_Day-86401;
// show the previous and next months-years in text format
$Next_Month=date("F",$Plus_Month);
$Prev_Month=date("F",$Minus_Month);
$Next_Year=date("Y",$Plus_Month);
$Prev_Year=date("Y",$Minus_Month);
// set the column width of each weekday in the calendar
$col_width="90";
// now we draw the Calendar header as the start of an HTML table
// we'll need to close it later with a </table> tag
echo "
<table border='1'>
<tr align='center' border='0'>
<td align='center' colspan='7' bgcolor=\"#000080\"><font face=\"Tahoma\" size=6 color=\"white\">I-DEP Deposition Calendar</font></td>
</tr>
<tr align='center' border='0'>
<td align='center' colspan='7' bgcolor=\"#ccccff\">
<font face=\"Tahoma\" size=4 color=\"black\"><B>$This_Month $This_Year</font>
</td>
</tr>
<tr>
<td colspan='2'>
<a href='?Month=$Prev_Month&Year=$Prev_Year'> << Previous Month</a>
</td>
<td colspan='3' align='center'>
<a href='?'>Reset to Current Month</a>
</td>
<td colspan='2' align='right'>
<a href='?Month=$Next_Month&Year=$Next_Year'>Next Month >> </a>
</td>
</tr>
<tr>
<td width='$col_width' align='center' bgcolor=\"#000080\"><font face=\"Tahoma\" size=3 color=\"white\"><B>Sunday</td>
<td width='$col_width' align='center' bgcolor=\"#ccccff\"><font face=\"Tahoma\" size=3 color=\"black\"><B>Monday</td>
<td width='$col_width' align='center' bgcolor=\"#ccccff\"><font face=\"Tahoma\" size=3 color=\"black\"><B>Tuesday</td>
<td width='$col_width' align='center' bgcolor=\"#ccccff\"><font face=\"Tahoma\" size=3 color=\"black\"><B>Wednesday</td>
<td width='$col_width' align='center' bgcolor=\"#ccccff\"><font face=\"Tahoma\" size=3 color=\"black\"><B>Thursday</td>
<td width='$col_width' align='center' bgcolor=\"#ccccff\"><font face=\"Tahoma\" size=3 color=\"black\"><B>Friday</td>
<td width='$col_width' align='center' bgcolor=\"#000080\"><font face=\"Tahoma\" size=3 color=\"white\"><B>Saturday </td>
</tr> ";
// This assumes the Calendar Header was written with the Calendar_Header()
// function in the library.php code library.
//First, get the information needed to choose what calendar to display
$Month=$_GET['Month'];
$Year=$_GET['Year'];
//If no month or year to get, set to current month and year...
$now=time();
if ($Month=="")
$Month=date("F",$now);
if ($Year=="")
$Year=date("Y",$now);
//How many days in the month?
switch($Month)
{
case "January" :
$days="31";
break;
case "February" :
if ($Year%4=="0") $days="29";
else $days="28";
break;
case "March" :
$days="31";
break;
case "April" :
$days="30";
break;
case "May" :
$days="31";
break;
case "June" :
$days="30";
break;
case "July" :
$days="31";
break;
case "August" :
$days="31";
break;
case "September" :
$days="30";
break;
case "October" :
$days="31";
break;
case "November" :
$days="30";
break;
case "December" :
$days="31";
break;
}
//Next we determine what day of the week is the first day of the month
$Day="Sunday";
$Daynum=strtotime("$Month 1 $Year");
$Day=date("l",$Daynum);
//Assign positions to days of week and identify the starting day
switch($Day)
{
case "Monday" :
$startpos="2";
break;
case "Tuesday" :
$startpos="3";
break;
case "Wednesday" :
$startpos="4";
break;
case "Thursday" :
$startpos="5";
break;
case "Friday" :
$startpos="6";
break;
case "Saturday" :
$startpos="7";
break;
case "Sunday" :
$startpos="1";
break;
}
//next we need to determine how many rows of seven columns we need
$basenum=$startpos+$days-1;
$rows=ceil($basenum/7);
//Next, we draw the calendar body
$rowcount="1";
$daycount="1";
$calendar_day=0;
while ($rowcount<=$rows)
{
echo "<tr>";
$day_column=1;
while ($day_column<=7)
{
echo "<td>";
if ($daycount<$startpos)
echo " ";
elseif (($daycount-$startpos+1)>$days)
echo " ";
else
{
$calendar_day=$calendar_day+1;
echo ' <a href="depday.php?Year='.$Year.'&Month='.$Month.'&Day='.$calendar_day.'"> '.$calendar_day,'</a> ';
// echo "$calendar_day";
}
$daycount=$daycount+1;
echo "</td>";
$day_column=$day_column+1;
}
echo "</tr>";
$rowcount=$rowcount+1;
}
//Finally, we finish the table
echo "</table>";
//echo test variables
//echo "start position is $startpos<br/>";
//echo "Month is $Month<br/>";
//echo "Year is $Year<br/>";
//echo "Starting Day is $day<br/>";
?>
And where I edit a record:
<?php
// Connect to database
$connect= mysql_connect("localhost","root")
or die("Could not connect to database in localhost !");
mysql_select_db("testdiw")
or die("Could not select that database !");
$newdate_string = $newdepyear . "-" . $newdepmonth . "-" . $newdepday;
if(!empty($_REQUEST['action']) && $_REQUEST['action'] == 'update')
{
$id = $_REQUEST['id'];
$_GET['id'] = $id;
$query = "UPDATE `diw_alpha` SET diwtitle = '".$_REQUEST['newtitle']."', depstatus = '".$_REQUEST['newdepstatus']."', date_string ='".$_REQUEST['newdepdate']."'WHERE id='$id'";
$result = mysql_query($query) or die("<b>mySQL Error:</b>".mysql_errono()."<br>".mysql_error());
if(!$result)
{
echo 'Error processing request.';
}
else
{
echo '<B>The DIW has been successfully updated!</B>';
}
}
$id = $_GET['id'];
// The ID is passed through the URL to specify the row,
// Or it is set in the previous script.
$query = "SELECT * FROM diw_alpha WHERE id = '$id'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
echo '
<tr>
<td ><font face="Tahoma" size=2 color="black"><b>DIW Title</b></font></td>
<td><font face="Tahoma" size=2 color="black">'.$row['diwtitle'].'</font></td>
</tr>
<tr>
<td><font face="Tahoma" size=2 color="black"><b> Deposition Time</b></font></td>
<td><font face="Tahoma" size=2 color="black">'.$row['deptimehour'].':'.$row['deptimeminute'].' '.$row['depampm'].'</font></td>
</tr>
help!