Forum Moderators: coopster
I've spent the past two days trying to build a php calander, based on a decent tutorial i found, but i needed to modify it to meet additional needs and then to integrate with the mysql backend.
I've done most of it, but i'm been plagued by one problem and the final part of the mod ...
I've set a query to run to check the dbase to see if there are any entries for dates within that month. I've set a start date and an end date. The problem is that is is only showing up the date when the first entry is located, ie if there is an entry on the 15, one on the 20 and one on 23, then the 20 and 23 do not show as having entries. I'm guessing i need to add a loop in somewhere to get the system to recognise every entry, but after trying countless variations i've not found the answer.
I've pasted the code for part of the section below minus the loop sequence, if anybody can give me some pointers as to the right way or a better way then please let me know.
$date = $_GET['date'];
$start_date = date("Ym01", $date);
$end_date = date("Ym31", $date);
$iSQL = mysql_query("SELECT * FROM diary WHERE username='$username' AND family_id='$family_id' AND date BETWEEN '$start_date' AND '$end_date'");
while ($row = mysql_fetch_array($iSQL)) {
$entry = $row['date'];
$show_entry = strtotime($entry);
}
$entry_ok = $show_entry;
$i = 0;
foreach($weeks AS $week){
echo "<tr>\n";
foreach($week as $d){
if($i < $offset_count){
$day_link = "<a href=\"".$_SERVER['PHP_SELF']."?action=view_my_day&profile=".$profile."&date=".mktime(0,0,0,$month -1,$d,$year)."\">$d</a>";
echo "<td> </td>\n";
}
if(($i >= $offset_count) && ($i < ($num_weeks * 7) - $outset)){
$day_link = "<a href=\"".$_SERVER['PHP_SELF']."?action=view_my_day&profile=".$profile."&date=".mktime(0,0,0,$month,$d,$year)."\">$d</a>";
if($date == mktime(0,0,0,$month,$d,$year)){
echo "<td><B>$d</B></td>\n";
} else {
if($show_entry == mktime(0,0,0,$month,$d,$year)) {
echo "<td bgcolor=\"#DFDFDF\">$day_link</td>\n";
} else {
echo "<td bgcolor=\"#ffffff\">$day_link</td>\n";
}
}
} elseif(($outset > 0)) {
if(($i >= ($num_weeks * 7) - $outset)){
$day_link = "<a href=\"".$_SERVER['PHP_SELF']."?action=view_my_day&profile=".$profile."&date=".mktime(0,0,0,$month +1,$d,$year)."\">$d</a>";
echo "<td></td>\n";
}
}
$i++;
}
echo "</tr>\n";
}
Many Thanks in Advance,
Rob
I've never used the between so i may be wrong on this but if you quarry on a date between two dates it is only going to send you that date. so if
date = 05-05-15
start_date = 05-05-01
end_date = 05-05-30
then it will only return the 15th because the 15 is between the start and end dates.
I've been working on and off this prob for the last day or so, i get inspiration for how to get round it then hit another brick wall.
I'm now getting the sql statement (not the original one shown but a mod version) to return the mktime for all of the entries between the two dates, so i know that that part of the SQL is sort of doing its job.
I think i'm going to put the dates into an array and see if that works, but any other suggestions would be great.