pghutch Posted January 23, 2013 Share Posted January 23, 2013 I have a page where the day and date is displayed like this. < Previous Day - Wednesday January 23, 2013 > Next Day How do I make it so when the userclicks on < Previous Day link that they go to Tusday January 22, 2013 and when they lick on > Next Day they go to Thursday January 24, 2013 etc? Quote Link to comment Share on other sites More sharing options...
scootstah Posted January 23, 2013 Share Posted January 23, 2013 Check out strtotime strtotime('-1 day'); strtotime('+1 day'); Quote Link to comment Share on other sites More sharing options...
pghutch Posted January 23, 2013 Author Share Posted January 23, 2013 Well I am pretty new to PHP So any other code will hep me. Ive started with this but how do I add code to the actual labels here < Previous Day - Wednesday January 23, 2013 > Next Day What code goes on < Previous Day and > Next Day? Heres what I have so far <?php $date = isset($_GET['date']) ? $_GET['date'] : date('Y-m-d'); $previous_date = date('Y-m-d', strtotime($date .' -1 day')); $next_date = date('Y-m-d', strtotime($date .' -1 day')); ?> Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 23, 2013 Share Posted January 23, 2013 Those would just be links. The code that gets the content for the page is where you'd change the date. Quote Link to comment Share on other sites More sharing options...
pghutch Posted January 23, 2013 Author Share Posted January 23, 2013 So I now have this. But the links don't go to the next or previous day. The links look like this /index.php?date=<?=$next_date;?>. Where they should actually pass a actual date instead of "<?=$next_date;?>." <?php $date = isset($_GET['date']) ? $_GET['date'] : date('Y-m-d'); $previous_date = date('Y-m-d', strtotime($date .' -1 day')); $next_date = date('Y-m-d', strtotime($date .' -1 day')); ?> <a href="?date=<?=$previous_date;?>">Previous</a> <a href="?date=<?=$next_date;?>">Next</a> Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 23, 2013 Share Posted January 23, 2013 You need to use full tags not short ones. Quote Link to comment Share on other sites More sharing options...
pghutch Posted January 23, 2013 Author Share Posted January 23, 2013 Jessica, Can you show me how to do that? Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 23, 2013 Share Posted January 23, 2013 Use <?php echo not <?=. *smh* Quote Link to comment Share on other sites More sharing options...
Christian F. Posted January 23, 2013 Share Posted January 23, 2013 You also need to (re-)read the page that Scootstah linked you to, as your use of strtotime () is incorrect. Quote Link to comment Share on other sites More sharing options...
pghutch Posted January 23, 2013 Author Share Posted January 23, 2013 OK here is where I am now. I appreciate all of the help. But still no dates are passed in the url....its blank, like this. The links look like this..../index.php?date= Heres my code <?php $date = isset($_GET['date']) ? $_GET['date'] : date('Y-m-d'); $previous_date = date('Y-m-d', strtotime($date .' -1 day')); $next_date = date('Y-m-d', strtotime($date .' +1 day')); ?> <a href="index.php?<?php echo date?>=<?php echo $row->$previous_date;?>" > Previous </a>;?> Todays Date <a href="index.php?<?php echo date?>=<?php echo $row->$next_date;?>" > Next </a>;?> Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 23, 2013 Share Posted January 23, 2013 Why did you add $row?? Come on... Quote Link to comment Share on other sites More sharing options...
pghutch Posted January 23, 2013 Author Share Posted January 23, 2013 Well thanks to everyone's help I've gotten the previous and next to work. But I have one last question. I want my date formatted like this: Wednesday January 23, 2012 Right now with the code below the date is outputting like this 2013-01-28. How can I output this <span class="datetxt"> <?php echo $_GET['date'];?></span> to this Wednesday January 23, 2012 Here is the code. <?php echo '<h3 class="home-title">Schedule for Today<span class="date">';?> <a href="index.php?<?php echo date?>=<?php echo $previous_date;?>" > <img src="assets/images/lftarrow.png" width="28" height="12"> </a> <span class="datetxt"> <?php echo $_GET['date'];?></span> <a href="index.php?<?php echo date?>=<?php echo $next_date;?>" ><img src="assets/images/rtarrow.png" width="28" height="12"></a> </span></h3> Quote Link to comment Share on other sites More sharing options...
Psycho Posted January 23, 2013 Share Posted January 23, 2013 (edited) I would suggest that instead of passing strings such as "2012-01-05" as the parameter on the URL - just send an offset from the current date (i.e. +5). It will make your code cleaner and validation simpler (which you are not doing now). It also helps in that you don't have to manipulate a lot of strings. Keep data in as simple/agnostic a format as possible until needed. <?php //Get offset from URL parameter, default is 0 $offset = isset($_GET['offset']) ? intval($_GET['offset']) : 0; //Define display date using current date and the offset $display_date = date('l F j, Y', strtotime("$offset days")); //Determine prev/next offsets based on current offset $prev_off = $offset - 1; $next_off = $offset + 1; ?> <h3 class="home-title"> Schedule for Today <span class="date"> <a href="test.php?offset=<?php echo $prev_off; ?>"><img src="assets/images/lftarrow.png" width="28" height="12"></a> <span class="datetxt"><?php echo $display_date;?></span> <a href="test.php?offset=<?php echo $next_off; ?>"><img src="assets/images/rtarrow.png" width="28" height="12"></a> </span> </h3> Edited January 23, 2013 by Psycho Quote Link to comment Share on other sites More sharing options...
pghutch Posted January 24, 2013 Author Share Posted January 24, 2013 Holy Cow!!!! Now that's answer!! Thank you so much. I'm new to PHP and these forums. Is there a way that I check that you gave me the correct answer? Quote Link to comment Share on other sites More sharing options...
scootstah Posted January 24, 2013 Share Posted January 24, 2013 Is there a way that I check that you gave me the correct answer? Yes, there is a "Mark Solved" button at the top of this thread. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.