ROCKINDANO Posted June 30, 2011 Share Posted June 30, 2011 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 https://forums.phpfreaks.com/topic/240802-need-help-creating-date-links/ Share on other sites More sharing options...
Maq Posted June 30, 2011 Share Posted June 30, 2011 What part do you need help with? Link to comment https://forums.phpfreaks.com/topic/240802-need-help-creating-date-links/#findComment-1236808 Share on other sites More sharing options...
ROCKINDANO Posted June 30, 2011 Author Share Posted June 30, 2011 after displaying the page with current date, i want to have two links on top. one for "prev month" and the other for "next month" Link to comment https://forums.phpfreaks.com/topic/240802-need-help-creating-date-links/#findComment-1236811 Share on other sites More sharing options...
EdwinPaul Posted June 30, 2011 Share Posted June 30, 2011 <?php $previous_month=date("m")-1; $this_month=date("m"); $next_month=date("m")+1; ?> Can you do something with this? Link to comment https://forums.phpfreaks.com/topic/240802-need-help-creating-date-links/#findComment-1236894 Share on other sites More sharing options...
ROCKINDANO Posted June 30, 2011 Author Share Posted June 30, 2011 well i see where your going. but how would i use that in the link? Link to comment https://forums.phpfreaks.com/topic/240802-need-help-creating-date-links/#findComment-1236902 Share on other sites More sharing options...
xyph Posted June 30, 2011 Share Posted June 30, 2011 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 https://forums.phpfreaks.com/topic/240802-need-help-creating-date-links/#findComment-1236907 Share on other sites More sharing options...
ROCKINDANO Posted July 1, 2011 Author Share Posted July 1, 2011 Not working................. Link to comment https://forums.phpfreaks.com/topic/240802-need-help-creating-date-links/#findComment-1237298 Share on other sites More sharing options...
PFMaBiSmAd Posted July 1, 2011 Share Posted July 1, 2011 <?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 https://forums.phpfreaks.com/topic/240802-need-help-creating-date-links/#findComment-1237305 Share on other sites More sharing options...
ROCKINDANO Posted July 5, 2011 Author Share Posted July 5, 2011 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 https://forums.phpfreaks.com/topic/240802-need-help-creating-date-links/#findComment-1238590 Share on other sites More sharing options...
EdwinPaul Posted July 5, 2011 Share Posted July 5, 2011 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 https://forums.phpfreaks.com/topic/240802-need-help-creating-date-links/#findComment-1238601 Share on other sites More sharing options...
PFMaBiSmAd Posted July 5, 2011 Share Posted July 5, 2011 The $date variable contains a YYYY-MM value. In order to select matching information from your table, you would need to use just the YYYY-MM part of actDate in the query. Link to comment https://forums.phpfreaks.com/topic/240802-need-help-creating-date-links/#findComment-1238602 Share on other sites More sharing options...
PFMaBiSmAd Posted July 5, 2011 Share Posted July 5, 2011 is arithmetic ? ^^^ Inside a string it is not. $date = "$year-$month"; and $date = $year.'-'.$month; produce exactly the same result. Link to comment https://forums.phpfreaks.com/topic/240802-need-help-creating-date-links/#findComment-1238603 Share on other sites More sharing options...
ROCKINDANO Posted July 5, 2011 Author Share Posted July 5, 2011 yeah i tried that as a query also but no dice. $query="SELECT actID, actTitle, actTime, actPlace, actBody, date_format(actDate, '%Y %m') actDate FROM activities WHERE actDate = '$date'"; Link to comment https://forums.phpfreaks.com/topic/240802-need-help-creating-date-links/#findComment-1238604 Share on other sites More sharing options...
EdwinPaul Posted July 5, 2011 Share Posted July 5, 2011 is arithmetic ? ^^^ Inside a string it is not. $date = "$year-$month"; and $date = $year.'-'.$month; produce exactly the same result. Yes, I noticed. I removed it. :-\ Link to comment https://forums.phpfreaks.com/topic/240802-need-help-creating-date-links/#findComment-1238606 Share on other sites More sharing options...
ROCKINDANO Posted July 5, 2011 Author Share Posted July 5, 2011 solved. thank you all. modified my query to this. $query="SELECT actID, actTitle, actTime, actPlace, actBody, date_format(actDate, '%W, %M %d, %Y') actDate FROM activities WHERE YEAR(actDate) = '$year' AND MONTH(actDate) = '$month'"; Link to comment https://forums.phpfreaks.com/topic/240802-need-help-creating-date-links/#findComment-1238608 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.