Page 1 of 1
Problem with displaying a dynamic week
Posted: Tue Feb 28, 2006 10:39 pm
by ferio-moreno
Hello, i'm new here, at work, i've been developing a dynamic calendar. So far i have everything down, except one thing. I'm using alternate views like :month, week, & day. The month view was a breeze, but the week view..... I'm having a hardtime trying to get it to actually few 7 days at a time, and then by clicking on 'previous' or 'next', I would like for it to then display the next/previous week. Here's the basic layout of what i'm working with. I was know that i'm obviously doing something wrong, but I can't quite get my finger on it, i'm still quite new to php btw

I'll take any help I can get. thx. again.
Code: Select all
<table>
<tr>
<td>S</td>
<td>M</td>
<td>T</td>
<td>W</td>
<td>T</td>
<td>F</td>
<td>S</td>
</tr>
<tr>
<?php
$today = date('d'); //for today's date
$days = date('t'); //for how many days are in this month
$wday = date('w'); //for the day number in current week
for ($i=0; $i<=6; $i++) {
if ($today > $days){
$today = 1;
}
echo "<td>";
if ($wday > $i){
echo $today-$wday;
} else {
echo $today++;
}
echo "</td>";
}
?>
</tr>
</table>
(the previous and next buttons were removed temporarily until i could get it to actually display the dates in the right places)
Posted: Wed Mar 01, 2006 10:54 am
by ferio-moreno
please folks i'm begging for some advice, i've been trying constantly all night with no positive results, please any feedback?
Posted: Wed Mar 01, 2006 11:16 am
by matthijs
don't know what you want to do exactly, but you could check out the calendar christian heilmann made
http://icant.co.uk/articles/online-chri ... /index.php. You might find some inspiration there.
Posted: Wed Mar 01, 2006 11:19 am
by feyd
It's hard to understand what you actually need help on. So all I can offer is play with
mktime() and
strtotime().
Posted: Wed Mar 01, 2006 12:31 pm
by ferio-moreno
sry, but what i was trying to do was getting a weekly view of my calendar to display, and by clicking next or previous it displays the next week after.
Posted: Wed Mar 01, 2006 1:35 pm
by ferio-moreno
you know how dynamic calendars have a month view, a week view, and a day view?
i'm trying to make the week view work, but i'm having alot of problems with it.... any pointers?
Posted: Wed Mar 01, 2006 1:40 pm
by matthijs
I think that the best thing you can do is check out some existing scripts (maybe hotscrips or google some), see what they do and how they work. Learn from them and piece together your script based on them. Then post some code here so others can review it. Sorry I cannot give you a concrete piece of code, but maybe this advice help you a bit further
Posted: Wed Mar 01, 2006 1:55 pm
by feyd
Your (ferio) further posts have only reiterated what you've said already. I still have no idea what you need help with direction wise.
Posted: Wed Mar 01, 2006 2:39 pm
by ferio-moreno
i was wondering what i did wrong in the php area of my code why the right dates wont show up on the right days.
(sorry, i know i'm not good at explaining things)
Posted: Wed Mar 01, 2006 2:45 pm
by feyd
This finds sunday of the current week.
Code: Select all
$sunday = mktime(0,0,0,date('n'),date('j')-date('w'),date('Y'));
Posted: Wed Mar 01, 2006 3:08 pm
by Fractal
You mean like, instead of viewing months/days/years at a time.. If you have a section to view weeks only?
Code: Select all
$dim = date(""); // Days in month
$today = date(""); // Todays day #
$day = $_GET['day']; // Determined by day # (address bar)
$month = $_GET['month']; // Determined by a month # (address bar)
$year = $_GET['year']; // Determined by a year # (address bar)
if ($day || $month || $year) {
if ($day > $dim || $day < "1") {
echo "<tr><td>You have selected an invalid day of the month.<br /></td></tr>\n";
} else {
if ($month > "12" || $month < "1") {
echo "<tr><td>You have selected an invalid month.<br /></td></tr>\n";
} else {
if ($year < "1") {
echo "<tr><td>You have selected an invalid year.<br /></td></tr>\n";
} else {
echo "<tr>";
$w = $day + "7";
for ($x = $day; $x <= $w; $x++) {
if ($x == $w) $break = "</tr>\n<tr>";
echo "<td>".(Weekday depending on day #)."</td>".$break;
if ($x = $today) { $td = "<td bgcolor='#E5E5E5'>"; } else { $td = "<td>"; }
echo $td.$x."</td>";
}
echo "</tr>\n";
}
}
} else {
// redirect/return an error/include whatever
}
Now, you'd have to edit it because it'll have flaws
For example, if was to make $day = 28 and $month = 2 (february), it'd echo "28, 29, 30, 31, 32, 33, 34"
But I think that's what you're trying to do. o_O