Jump to content

Need help creating date links


ROCKINDANO

Recommended Posts

Hello all,

 

I need some assistance in creating links for a calendar that is db driven. below are my tables schema:

 

activities (actID int(20),actTitle varchar(100),actTime varchar(25),actPlace text,actBody text,actDate date,file text)

 

can some one point me to the right direction?

 

below is my query in my php file.

 

				$query="SELECT actID, actTitle, actTime, actPlace, actBody, date_format(actDate, '%W, %M, %d %Y') actDate, actDate as sortdate, file FROM activities WHERE actDate > '$today2' ORDER BY sortdate ASC";
			$result=mysql_query($query);

			while($r=mysql_fetch_array($result))
			{
				//modify these to match your mysql table columns
				$actID=$r["actID"];
				$actTitle=$r["actTitle"];
				$actBody=$r["actBody"];
				$actDate=$r["actDate"];
				$file=$r["file"];
				$actTime=$r["actTime"];
				$actPlace=$r["actPlace"];

 

HELP!!!

Link to comment
Share on other sites

calendar.php?month=10&year=2011

 

$_GET['month'] = (int) $_GET['month'];
$_GET['year'] = (int) $_GET['year'];

$query = 'SELECT `columns` FROM `table` WHERE
MONTH(`actDate`) = '.$_GET['month'].' AND YEAR(`actDate`) = '.$_GET['year'];

Link to comment
Share on other sites

<?php

// get the date from the URL or get the current date
$month = isset($_GET['month']) ? sprintf('%02d',(int)$_GET['month']) : date('m');
$year = isset($_GET['year']) ? (int)$_GET['year'] : date('Y');
$date = "$year-$month";

// determine previous/next month (valid from 1970 (or 1901, depending on php version and operating system) through  2038 only)
$previous = explode('-',date('Y-m',strtotime($date . '-1 -1 month')));
$next = explode('-',date('Y-m',strtotime($date . '-1 +1 month')));

// produce previous/next link
$query = (empty($_GET)) ? array() : $_GET; // get an empty array if no existing $_GET parameters or get the current $_GET parameters
$query['month'] = $previous[1]; // set or replace the month parameter
$query['year'] = $previous[0]; // set or replace the year parameter
$prev_link = "<a href='?" . http_build_query($query, '', '&') . "'><img src='prev_month.png' alt=''></a>";
$query['month'] = $next[1]; // set or replace the month parameter
$query['year'] = $next[0]; // set or replace the year parameter
$next_link = "<a href='?" . http_build_query($query, '', '&') . "'><img src='next_month.png' alt=''></a>";

// output the links
echo $prev_link  . " Previous Month Current date: $date Next Month " . $next_link;
?>

Link to comment
Share on other sites

why does my query return 0 if i do have events for this month.

 

// get the date from the URL or get the current date
$month = isset($_GET['month']) ? sprintf('%02d',(int)$_GET['month']) : date('m');
$year = isset($_GET['year']) ? (int)$_GET['year'] : date('Y');
$date = "$year-$month";

// determine previous/next month (valid from 1970 (or 1901, depending on php version and operating system) through  2038 only)
$previous = explode('-',date('Y-m',strtotime($date . '-1 -1 month')));
$next = explode('-',date('Y-m',strtotime($date . '-1 +1 month')));

// produce previous/next link
$query = (empty($_GET)) ? array() : $_GET; // get an empty array if no existing $_GET parameters or get the current $_GET parameters
$query['month'] = $previous[1]; // set or replace the month parameter
$query['year'] = $previous[0]; // set or replace the year parameter
$prev_link = "<a href='?" . http_build_query($query, '', '&') . "'><img src='prev_month.png' alt=''>Prev</a>";
$query['month'] = $next[1]; // set or replace the month parameter
$query['year'] = $next[0]; // set or replace the year parameter
$next_link = "<a href='?" . http_build_query($query, '', '&') . "'><img src='next_month.png' alt=''>Next</a>";

// output the links
echo $prev_link  . "" . $next_link;
?>
<?php
					if(!($db = @ mysql_connect('localhost', 'username', '98098089')))
		{
			echo 'Error: Could not connect to our database sorry for any inconvience.<br /> Please try at a later time.';
			exit;
		}
		mysql_select_db("edinburg_site");
		$actID= $_GET["actID"];

		if(!isset($actID) && !isset($typeview))
		{
//					$today = date('l, F jS, Y');
//					$today2 = date('Y-m-j');

			$actDate=$_GET["actDate"];

//			$query="SELECT actID, actTitle, actBody, date_format(actDate, '%W, %M, %Y') actDate, file FROM activities WHERE actDate='$today2'";
			$query="SELECT actID, actTitle, actTime, actPlace, actBody, date_format(actDate, '%Y %m') FROM activities WHERE actDate = '$date'";
			print $query;
			$result=mysql_query($query);

Link to comment
Share on other sites

why does my query return 0 if i do have events for this month.

 

// get the date from the URL or get the current date
$month = isset($_GET['month']) ? sprintf('%02d',(int)$_GET['month']) : date('m');
$year = isset($_GET['year']) ? (int)$_GET['year'] : date('Y');
$date = "$year-$month";

// determine previous/next month (valid from 1970 (or 1901, depending on php version and operating system) through  2038 only)
$previous = explode('-',date('Y-m',strtotime($date . '-1 -1 month')));
$next = explode('-',date('Y-m',strtotime($date . '-1 +1 month')));

// produce previous/next link
$query = (empty($_GET)) ? array() : $_GET; // get an empty array if no existing $_GET parameters or get the current $_GET parameters
$query['month'] = $previous[1]; // set or replace the month parameter
$query['year'] = $previous[0]; // set or replace the year parameter
$prev_link = "<a href='?" . http_build_query($query, '', '&') . "'><img src='prev_month.png' alt=''>Prev</a>";
$query['month'] = $next[1]; // set or replace the month parameter
$query['year'] = $next[0]; // set or replace the year parameter
$next_link = "<a href='?" . http_build_query($query, '', '&') . "'><img src='next_month.png' alt=''>Next</a>";

// output the links
echo $prev_link  . "" . $next_link;
?>
<?php
					if(!($db = @ mysql_connect('localhost', 'username', '98098089')))
		{
			echo 'Error: Could not connect to our database sorry for any inconvience.<br /> Please try at a later time.';
			exit;
		}
		mysql_select_db("edinburg_site");
		$actID= $_GET["actID"];

		if(!isset($actID) && !isset($typeview))
		{
//					$today = date('l, F jS, Y');
//					$today2 = date('Y-m-j');

			$actDate=$_GET["actDate"];

//			$query="SELECT actID, actTitle, actBody, date_format(actDate, '%W, %M, %Y') actDate, file FROM activities WHERE actDate='$today2'";
			$query="SELECT actID, actTitle, actTime, actPlace, actBody, date_format(actDate, '%Y %m') FROM activities WHERE actDate = '$date'";
			print $query;
			$result=mysql_query($query);

 

Why don't you echo some intermediate results?

<?php
$date = "$year-$month";
echo $date."<br/>";
echo date('Y-m',strtotime($date . '-1 -1 month'))."<br/>";
echo date('Y-m',strtotime($date . '-1 +1 month'))."<br/>";
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.