Link to home
Start Free TrialLog in
Avatar of Larry Vollmer
Larry Vollmer

asked on

Loop question

I have the following code:

 <?php
                  for ($i =0, $t = time(); $i< 7; ++$i) {
                      echo strftime('<li class = "inline">%a <br /><a href="http://calendar.site.com/app.php?tab=events&query=&site=name&tpl=EventSearchAllESD&SearchKeyword=&SearchDate=%Y%m%d&SearchDateEnd=%Y%m%d&SearchLocation=&SearchPrice=&SearchCategory"> %d</a>', $t+$i*3600*24) ."</li>";
                  }
       ?>

the code just produces 7 different list items and the appropriate date string in the URL

I need to modify the code to display 7 different div's and I am having trouble

<!-- THIS IS THE FIRST DIV - ID = 0 -->
            <div class="square" id="day0">
                  <a href="href="http://calendar.site.com/app.php?tab=events&query=&site=name&tpl=EventSearchAllESD&SearchKeyword=&SearchDate=%Y%m%d&SearchDateEnd=%Y%m%d&SearchLocation=&SearchPrice=&SearchCategory">
            </div>

<!-- THIS IS THE SECOND DIV - ID = 1 -->
            <div class="square" id="day1">
                  <a href="href="http://calendar.site.com/app.php?tab=events&query=&site=name&tpl=EventSearchAllESD&SearchKeyword=&SearchDate=%Y%m%d&SearchDateEnd=%Y%m%d&SearchLocation=&SearchPrice=&SearchCategory">
            </div>

<!-- THIS IS THE THIRD DAY DIV - ID = 2 -->
            <div class="square" id="day2">
                  <a href="href="http://calendar.site.com/app.php?tab=events&query=&site=name&tpl=EventSearchAllESD&SearchKeyword=&SearchDate=%Y%m%d&SearchDateEnd=%Y%m%d&SearchLocation=&SearchPrice=&SearchCategory">
            </div>


this would go 7 days all the way to div id = 6

the SearchDate=%Y%m%d&SearchDateEnd=%Y%m%d& in the URL would also have to reflect the proper date.

Can anyone help me out with this?
Avatar of Steve Bink
Steve Bink
Flag of United States of America image

Just some small changes to your existing code:


<?php
  $searchdate=date('ymd',$_GET['SearchDate']);
  $searchenddate=date('ymd',$_GET['SearchEndDate']);
  for ($i =0, $t = time(); $i< 7; ++$i) {
    printf("<div class=\"square\" id=\"day%u\"><a href=\"http://calendar.site.com/app.php?tab=events&query=&site=name&tpl=EventSearchAllESD&SearchKeyword=&SearchDate=%s&SearchDateEnd=%s&SearchLocation=&SearchPrice=&SearchCategory\"></div>",$i,$searchdate,$searchenddate);
  }
?>

Open in new window

I forgot the link display text and the </a> to close the tag, but you should get the idea from that.
Avatar of Larry Vollmer
Larry Vollmer

ASKER

that kind of works, b ut all my dates are coming up as

691231

instead of the corresponding day of the week

http://calendar.site.com/app.php?tab=events&query=&site=name&tpl=EventSearchAllESD&SearchKeyword=&SearchDate=691231&SearchDateEnd=691231&SearchLocation=&SearchPrice=&SearchCategory
>>> [ ... ] SearchDate=691231 [ ... ]

That date is coming up as December 31, 1969.  Bad date parsing, is all.  Alter the code so that it is expecting a 4-digit year, and the fix below should work.  Note that the strtotime() call is redundant, but it does provide some basic conformity to the input data when it prints out the links.


<?php
  $searchdate=date('Ymd',strtotime($_GET['SearchDate']));
  $searchenddate=date('Ymd',strtotime($_GET['SearchEndDate']));
  for ($i =0, $t = time(); $i< 7; ++$i) {
    printf("<div class=\"square\" id=\"day%u\"><a href=\"http://calendar.site.com/app.php?tab=events&query=&site=name&tpl=EventSearchAllESD&SearchKeyword=&SearchDate=%s&SearchDateEnd=%s&SearchLocation=&SearchPrice=&SearchCategory\">link $i</a></div>",$i,$searchdate,$searchenddate);
  }
?>

Open in new window

I'm still getting 1969 with that code

&SearchDate=19691231&SearchDateEnd=19691231

also, the links are supposed to bring up the appropriate date

ie: if today is 12/04/2007

link0= &SearchDate=2007/12/04&SearchDateEnd=2007/12/04
link1= &SearchDate=2007/12/05&SearchDateEnd=2007/12/05
link2= &SearchDate=2007/12/06&SearchDateEnd=2007/12/06


etc..
sorry I was reffering to the other snippet of code. the last code you gave me doesnt provide any results at all
ASKER CERTIFIED SOLUTION
Avatar of Steve Bink
Steve Bink
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial