spacepoet Posted April 22, 2011 Share Posted April 22, 2011 Hi: How can I build a querystring (or whatever I need to do to solve my issue) to pull in the month and year? Meaning: I have this link: Entertainment.php which goes to a dynamic calendar, which works fine except it does not show the events because I think it replies on getting the current month and year. When I click on a "Next Month" and the click back to the current month, the URL is: Entertainment.php?month=4&year=2011 and the events then display properly in the calendar. How do I properly build a URL for this? The calendar code looks like this: <?php ob_start(); $today = date("M Y"); ?> ... <head> <script> function show_evt(m,y,day){ location.href = "<?=$_SERVER['PHP_SELF'];?>?month=" + m + "&year=" + y + "&day=" + day; } function goLastMonth(month, year) { if(month == 1) { --year; month = 13; } document.location.href = '<?=basename($_SERVER['PHP_SELF']);?>?month='+(month-1)+'&year='+year; } function goNextMonth(month, year) { if(month == 12) { ++year; month = 0; } document.location.href = '<?=basename($_SERVER['PHP_SELF']);?>?month='+(month+1)+'&year='+year; } </script> </head> ... <p> <?php $date =time (); $day = (isset($_GET['day'])) ? $_GET['day'] : date('d', $date); $month = (isset($_GET['month'])) ? $_GET['month'] : date('m', $date); $year = (isset($_GET['year'])) ? $_GET['year'] : date('Y', $date); $first_day = mktime(0,0,0,$month, 1, $year); $title = date('F', $first_day); $day_of_week = date('D', $first_day); switch($day_of_week){ case "Sun": $blank = 0; break; case "Mon": $blank = 1; break; case "Tue": $blank = 2; break; case "Wed": $blank = 3; break; case "Thu": $blank = 4; break; case "Fri": $blank = 5; break; case "Sat": $blank = 6; break; } $days_in_month = cal_days_in_month(0, $month, $year); ?> <table class="tableClass"> <tr class="field-bg-color"> <th class="eventLeftArrow"><a href="javascript: void(0);" onClick="goLastMonth(<?php echo $month . ", " . $year; ?>)"><<<</a></th> <th colspan="5" class="eventHeader"><?=$title. " " . $year;?></th> <th class="eventRightArrow"><a href="javascript: void(0);" onClick="goNextMonth(<?php echo $month . ", " . $year; ?>)">>>></a></th> </tr> <tr class="calDates"> <td>S</td> <td>M</td> <td>T</td> <td>W</td> <td>T</td> <td>F</td> <td class="lastOne">S</td> </tr> <?php $day_count = 1; ?> <tr> <?php while ( $blank > 0 ) { ?> <td> </td> <?php $blank = $blank-1; $day_count++; } $day_num = 1; while ( $day_num <= $days_in_month ) { $sql = "select count(calName) as evt_count from calTbl where calDate ='" . $month . '/' . $day_num . '/' . $year . "'"; $result = mysql_query($sql); while($row = mysql_fetch_array($result)){ if($row['evt_count'] >= 1){ ?> <td align="center" style="cursor:hand;cursor:pointer;background-color:#FF6A6A;text-align:center;" onclick="show_evt('<?=$month;?>','<?=$year;?>','<?=$day_num;?>');"> <div class="brown-bg-color cal-head-text white-text bold-text"><?=$day_num;?></div> <?php $sql = "select * from calTbl where calDate ='" . $month . '/' . $day_num . '/' . $year . "'"; $result = mysql_query($sql); while($row = mysql_fetch_array($result)){ ?> <a href="<?=$_SERVER['PHP_SELF'];?>?month=<?=$month;?>&year=<?=$year;?>&day=<?=$day_num;?>"><?=$row['calName'];?></a></br> <? } }else{ ?> <td> <div class="brown-bg-color cal-head-text"><?=$day_num;?></div> <?php } } ?> </td> <?php $day_num++; $day_count++; if ($day_count > 7){ ?> </tr><tr> <?php $day_count = 1; } } while ( $day_count >1 && $day_count <=7 ) { ?> <td> </td> <?php $day_count++; } ?> </tr></table> <?php if(isset($_GET['day'])){ $sql = "select * from calTbl where calDate ='" . $month . '/' . $_GET['day'] . '/' . $year . "'"; $result = mysql_query($sql); echo '<table class="data-table-class">'; echo '<th>Event Name</th><th>Event Desc</th>'; while($row = mysql_fetch_array($result)){ echo '<tr><td>'. $row['calName'] . '</td><td>' . $row['calDesc'] . '</td></tr>'; } echo '</table>'; } ?> <div class="myClear"></div> <?php ob_flush(); ?> </p> Can anyone help me out? This is the last part and I am good to go! Thanks! Link to comment https://forums.phpfreaks.com/topic/234456-need-help-with-querystring/ Share on other sites More sharing options...
fugix Posted April 22, 2011 Share Posted April 22, 2011 So you want to get te values of month and day from the URL? Link to comment https://forums.phpfreaks.com/topic/234456-need-help-with-querystring/#findComment-1204944 Share on other sites More sharing options...
spacepoet Posted April 22, 2011 Author Share Posted April 22, 2011 Hi: What I need to have happen is when the link is clicked: Entertainment.php It goes to that page with the final URL looking like: Entertainment.php?month=4&year=2011 Where the URL will always write the current month and year. Does this make sense? Thanks! Link to comment https://forums.phpfreaks.com/topic/234456-need-help-with-querystring/#findComment-1204970 Share on other sites More sharing options...
gevensen Posted April 22, 2011 Share Posted April 22, 2011 well $month=date("m"); will give you the month and $year=date("Y"); will give you the current year Im not sure you need to use $_GET for that Link to comment https://forums.phpfreaks.com/topic/234456-need-help-with-querystring/#findComment-1205007 Share on other sites More sharing options...
fugix Posted April 22, 2011 Share Posted April 22, 2011 if you do what gevesen said....next you will set the link href to Entertainment.php?month=$month&year=$year Link to comment https://forums.phpfreaks.com/topic/234456-need-help-with-querystring/#findComment-1205020 Share on other sites More sharing options...
spacepoet Posted April 22, 2011 Author Share Posted April 22, 2011 Got it! Entertainment.php?month=".date('n')."&year=".date('Y')."\" Thanks for the pointers - helped me to work through it. Link to comment https://forums.phpfreaks.com/topic/234456-need-help-with-querystring/#findComment-1205049 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.