Problem with displaying a dynamic week

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ferio-moreno
Forum Commoner
Posts: 30
Joined: Tue Feb 28, 2006 10:31 pm
Location: florida

Problem with displaying a dynamic week

Post 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)
Last edited by ferio-moreno on Wed Mar 01, 2006 8:30 am, edited 1 time in total.
ferio-moreno
Forum Commoner
Posts: 30
Joined: Tue Feb 28, 2006 10:31 pm
Location: florida

Post 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?
matthijs
DevNet Master
Posts: 3360
Joined: Thu Oct 06, 2005 3:57 pm

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

It's hard to understand what you actually need help on. So all I can offer is play with mktime() and strtotime().
ferio-moreno
Forum Commoner
Posts: 30
Joined: Tue Feb 28, 2006 10:31 pm
Location: florida

Post 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.
ferio-moreno
Forum Commoner
Posts: 30
Joined: Tue Feb 28, 2006 10:31 pm
Location: florida

Post 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?
matthijs
DevNet Master
Posts: 3360
Joined: Thu Oct 06, 2005 3:57 pm

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
ferio-moreno
Forum Commoner
Posts: 30
Joined: Tue Feb 28, 2006 10:31 pm
Location: florida

Post 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)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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'));
User avatar
Fractal
Forum Commoner
Posts: 54
Joined: Tue Aug 16, 2005 1:28 pm

Post 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
Post Reply