login  Naam:   Wachtwoord: 
Registreer je!
 Forum

Agenda met vorige volgende functie (Opgelost)

Offline GroundZero - 26/10/2012 21:03 (laatste wijziging 27/10/2012 12:40)
Avatar van GroundZeroLid Beste lezers,

ik laad mijn agenda in via een jQuery Ajax call.
Echter wil ik graag dat ik een volgende en vorige maand kan kiezen.

Echter krijg ik dit niet goed voor elkaar. Kan iemand mij aub vertellen hoe ik dit moet aanpakken en -of een voorbeeld code maken van de correcte functie?

Ik wil dus dat als er op vorige of volgende geklikt word, de timestamp word meegestuurd minus of plus één maand. Echter krijg ik de timestamp niet mee gestuurd.

De code die je onderaan ziet word al eens door een Ajax call geinclude in mijn index.php.

Mijn huidige code:

  1. // Get this months first day and last day in a timestamp
  2. if(isset($_POST['timestamp'])){
  3. $first_day = $_POST['timestamp'];
  4. } else {
  5. $first_day = strtotime(date("m/d/Y", strtotime(date('m').'/01/'.date('Y').' 00:00:00')));
  6. }
  7.  
  8. $last_day = strtotime(date("m/d/Y", strtotime('-1 second',strtotime('+1 month',strtotime(date('m').'/01/'.date('Y').' 00:00:00')))));
  9.  
  10. // Get time difference
  11. $minus = strtotime('-1 month', $first_day);
  12. $plus = strtotime('+1 month', $first_day);
  13.  
  14. // Display header
  15. echo '<div class="month">
  16. <div class="previous">
  17. <a href="#" title="Vorige maand" onclick="previousMonth('.$minus.'); return false;"><<</a>
  18. </div>
  19. <div class="monthName">
  20. '.date("F").'
  21. </div>
  22. <div class="next">
  23. <a href="#" title="Volgende maand" onclick="nextMonth('.$plus.'); return false;">>></a>
  24. </div>
  25.  
  26. </div>';
  27.  
  28. // Check amount of empty boxes to add
  29. $first_day_of_week = date("D", $first_day);
  30.  
  31. switch($first_day_of_week)
  32. {
  33. case 'Mon':
  34. $amount = 0;
  35. break;
  36.  
  37. case 'Tue':
  38. $amount = 1;
  39. break;
  40.  
  41. case 'Wed':
  42. $amount = 2;
  43. break;
  44.  
  45. case 'Thu':
  46. $amount = 3;
  47. break;
  48.  
  49. case 'Fri':
  50. $amount = 4;
  51. break;
  52.  
  53. case 'Sat':
  54. $amount = 5;
  55. break;
  56.  
  57. case 'Sun':
  58. $amount = 6;
  59. break;
  60. }
  61.  
  62. // Display the empty boxes
  63. $b = 1;
  64. for($c = 0; $c < $amount; $c++)
  65. {
  66. if($b % 7 != 0)
  67. {
  68. echo '<div class="day push-right b-space"></div>';
  69. }
  70. else
  71. {
  72. echo '<div class="day b-space"></div>';
  73. }
  74.  
  75. $b++;
  76. }
  77.  
  78. // Display all the other days
  79. $i = $b;
  80.  
  81. // Loop through the results and display the days
  82. while($first_day <= $last_day)
  83. {
  84. // Check for events
  85. $query = mysql_query('SELECT tekst FROM site_agenda
  86. WHERE
  87. datum = "'.mysql_real_escape_string(date("Y-m-d", $first_day)).'"');
  88. $rows = mysql_num_rows($query);
  89.  
  90. if($rows >= 1)
  91. {
  92. $a = ' booked';
  93. }
  94. else
  95. {
  96. $a = '';
  97. }
  98.  
  99. // Display
  100. if($i % 7 != 0)
  101. {
  102. echo '<div class="day push-right b-space'.$a.'">'.date("d", $first_day).'</div>';
  103. }
  104. else
  105. {
  106. echo '<div class="day b-space'.$a.'">'.date("d", $first_day).'</div>';
  107. }
  108.  
  109. // Add 1 day to the timestamp and up the counter
  110. $first_day += 60*60*24;
  111. $i++;
  112. }
  113. ?>
  114.  
  115. <script language="javascript" type="text/javascript">
  116. function nextMonth(adding){
  117. $.ajax({
  118. type: 'POST',
  119. url: 'includes/agenda.php',
  120. data: {
  121. timestamp : adding
  122. },
  123. success: function(html){
  124. $('#agendacall').html(html)
  125. }
  126. });
  127. }
  128.  
  129. function previousMonth(minus){
  130. $.ajax({
  131. type: 'POST',
  132. url: 'includes/agenda.php',
  133. data: {
  134. timestamp : minus
  135. },
  136. success: function(html){
  137. $('#agendacall').html(html)
  138. }
  139. });
  140. }
  141. </script>


EDIT:
Heb het nu werkend alleen gooit hij de dagen en lege velden een beetje in het honderd. Hopelijk kan iemand mij helpen alles correct te krijgen 

P.S. Excuses dat ik het in PHP sectie heb geplaatst, had het beter in JS sectie kunnen plaatsen  

0 antwoorden

Gesponsorde links
Er zijn nog geen reacties op dit bericht.
Je moet ingelogd zijn om een reactie te kunnen posten.
Actieve forumberichten
© 2002-2024 Sitemasters.be - Regels - Laadtijd: 0.317s