#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2010
    Posts
    87
    Rep Power
    4

    Can't Display Christmas Image


    Hi there,

    I am working on an advent calendar idea with 12 product deals. If we are on day one (which will be the 1st of December), I only want the first product deal to show. The remaining deals will be hidden by a christmas image. I have inherited some code that tries to solve this problem, however I can't seem to display the Christmas image for the remaining days? There is an else condition which is meant to display the christmas image if its not the right day. For some reason the else condition is not kicking in??

    I've not bothered so show all the CSS for the container divs etc but I think you get the idea that the products display in a box with a price, name, image rrp etc.

    Any help will be much appreciated.

    PHP Code:
    <?php
        $deal
    =array("1"=>array("image"=>"images/test1.jpg","link"=>"product1.html","name"=>"Test1","rrp"=>"&pound;29.99","salesprice"=>"&pound;10.00"),
                    
    "2"=>array("image"=>"images/test2.jpg","link"=>"product2.html","name"=>"Test2","rrp"=>"&pound;37.99","salesprice"=>"&pound;16.00"),
                    
    "3"=>array("image"=>"images/test3.jpg","link"=>"product3.html","name"=>"Test3","rrp"=>"&pound;39.99","salesprice"=>"&pound;25.00"),
                    
    "4"=>array("image"=>"images/test4.jpg","link"=>"product4.html","name"=>"Test4","rrp"=>"&pound;109.96","salesprice"=>"&pound;39.99"),
                    
    "5"=>array("image"=>"images/test5.jpg","link"=>"product5.html","name"=>"Test5","rrp"=>"&pound;39.99","salesprice"=>"&pound;25.00"),
                    
    "6"=>array("image"=>"images/test6.jpg","link"=>"product6.html","name"=>"Test6","rrp"=>"&pound;14.99","salesprice"=>"&pound;5.00"),
                    
    "7"=>array("image"=>"images/test7.jpg","link"=>"product7.html","name"=>"Test7","rrp"=>"&pound;74.99","salesprice"=>"&pound;50.00"),
                    
    "8"=>array("image"=>"images/test8.jpg","link"=>"product8.html","name"=>"Test8","rrp"=>"&pound;31.99","salesprice"=>"&pound;15.00"),
                    
    "9"=>array("image"=>"images/test9.jpg","link"=>"product9.html","name"=>"Test9","rrp"=>"&pound;39.99","salesprice"=>"&pound;25.00"),                                "10"=>array("image"=>"images/test10.jpg","link"=>"product10.html","name"=>"Test10","rrp"=>"&pound;19.99","salesprice"=>"&pound;10.00"),
                    
    "11"=>array("image"=>"images/test11.jpg","link"=>"product11.html","name"=>"Test11","rrp"=>"&pound;8.98","salesprice"=>"&pound;5.00"),
                    
    "12"=>array("image"=>"images/test12.jpg","link"=>"product12.html","name"=>"Test12","rrp"=>"&pound;64.99","salesprice"=>"&pound;40.00"));
        for(
    $d=1;$d<13;$d++)
        {
            
    $next=($d-(date("d")-6));
            if(
    $d<=date("d")-6)echo "<a href=\"".$deal[$d]['link']."\"><div class=\"dealbox\"><h2>".($d).": ".$deal[$d]['name']."</h2><div class=\"container\"><img src=\"".$deal[$d]['image']."\"></div><div class=\"bottom\">RRP: ".$deal[$d]['rrp']."<br><span style=\"color:red;\"><b>Now: ".$deal[$d]['salesprice']."!</b></span></div></div></a>";
            else echo 
    "<div class=\"dealbox\"><h2>Opens in ".$next." day".($next==1?"":"s")."!</h2><div class=\"container\" style=\"height:150px;\"><img src=\"images/home/christmas-presents.jpg\" style=\"max-height:150px;\"></div></div>";
        }
    ?>
    Last edited by volterony; November 28th, 2012 at 07:55 AM.
  2. #2
  3. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,692
    Rep Power
    6351
    1) Advent isn't 12 days (that's Saturnalia); Advent is 22-29 days depending on the year.

    2) This code displays a christmas image depending on the current day of the month minus six. It's not going to work for you today since it's the 28th, it will always display all the images.

    To test this, replace date("d") with a hard-coded value for the day you're trying to test, then adjust your math until it behaves the way you want.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2010
    Posts
    87
    Rep Power
    4
    Thanks for your help there.

    Yes granted, Advent is a totally different thing

    Yes Maniac Dan, I've noodled about and passed in the 1st of December as the date minus 9, so the first product will appear on the 7th of December and they will run up until the 24th. Obviously this can be configured to run for whatever duration we specify.

    Thanks very much for your help.

    Regards
    Volterony

IMN logo majestic logo threadwatch logo seochat tools logo