eRott Posted April 14, 2009 Share Posted April 14, 2009 Hi there, I am looking for a bit of input / assistance. I am currently working on a project whereby I need to display an inline list of dates with some various information. Below is a photo of the finished result. When you click on a date block, it pops up additional information (or, it will I should say), making use of your typical ThickBox / Lightbox window. It works the way I intend it to. My concern is with my approach and my use of PHP code to accomplish the displaying of this section. I get the feeling / sense that its a little heavier then it needs to be. I am just wondering if anyone would be willing to give their input or ideas as to a means of simplifying my code or an easier method of doing what I have done. <ul id="events"> <?php $month = date(n); $year = date(Y); $today = date(j); ?> <li><a href="" title="<?php $var = $today - 3; $day = mktime(0, 0, 0, $month, $var, $year); echo date("l",$day) . ", " . date("F",$day) . " " . date("jS",$day); ?>" class="thickbox"><div class="block"><div class="d"><?php $var = $today - 3; $day = mktime(0, 0, 0, $month, $var, $year); echo date("D",$day); ?></div><div class="day"><?php echo $today - 3; ?></div><div class="pvp">PvP</div></div></a></li> <li><a href="" title="<?php $var = $today - 2; $day = mktime(0, 0, 0, $month, $var, $year); echo date("l",$day) . ", " . date("F",$day) . " " . date("jS",$day); ?>" class="thickbox"><div class="block"><div class="d"><?php $var = $today - 2; $day = mktime(0, 0, 0, $month, $var, $year); echo date("D",$day); ?></div><div class="day"><?php echo $today - 2; ?></div><div class="raid">Raid</div></div></a></li> <li><a href="" title="<?php $var = $today - 1; $day = mktime(0, 0, 0, $month, $var, $year); echo date("l",$day) . ", " . date("F",$day) . " " . date("jS",$day); ?>" class="thickbox"><div class="block"><div class="d"><?php $var = $today - 1; $day = mktime(0, 0, 0, $month, $var, $year); echo date("D",$day); ?></div><div class="day"><?php echo $today - 1; ?></div><div class="heroic">Heroic</div></div></a></li> <li><a href="" title="<?php $day = mktime(0, 0, 0, $month, $today, $year); echo date("l",$day) . ", " . date("F",$day) . " " . date("jS",$day); ?>" class="thickbox"><div class="block-today"><div class="d"><?php $day = mktime(0, 0, 0, $month, $today, $year); echo date("D",$day); ?></div><div class="day"><?php echo $today; ?></div><div class="heroic">Heroic</div></div></a></li> <li><a href="" title="<?php $var = $today + 1; $day = mktime(0, 0, 0, $month, $var, $year); echo date("l",$day) . ", " . date("F",$day) . " " . date("jS",$day); ?>" class="thickbox"><div class="block"><div class="d"><?php $var = $today + 1; $day = mktime(0, 0, 0, $month, $var, $year); echo date("D",$day); ?></div><div class="day"><?php echo $today + 1; ?></div><div class="heroic">Heroic</div></div></a></li> <li><a href="" title="<?php $var = $today + 2; $day = mktime(0, 0, 0, $month, $var, $year); echo date("l",$day) . ", " . date("F",$day) . " " . date("jS",$day); ?>" class="thickbox"><div class="block"><div class="d"><?php $var = $today + 2; $day = mktime(0, 0, 0, $month, $var, $year); echo date("D",$day); ?></div><div class="day"><?php echo $today + 2; ?></div><div class="raid">Raid</div></div></a></li> <li><a href="" title="<?php $var = $today + 3; $day = mktime(0, 0, 0, $month, $var, $year); echo date("l",$day) . ", " . date("F",$day) . " " . date("jS",$day); ?>" class="thickbox"><div class="block"><div class="d"><?php $var = $today + 3; $day = mktime(0, 0, 0, $month, $var, $year); echo date("D",$day); ?></div><div class="day"><?php echo $today + 3; ?></div><div class="pvp">PvP</div></div></a></li> </ul> Thanks. Take it easy. Link to comment https://forums.phpfreaks.com/topic/154133-code-cleanup/ Share on other sites More sharing options...
MasterACE14 Posted April 14, 2009 Share Posted April 14, 2009 could loop it. Just make the one list item, and throw in the loop around it to generate the rest. Link to comment https://forums.phpfreaks.com/topic/154133-code-cleanup/#findComment-810237 Share on other sites More sharing options...
eRott Posted April 14, 2009 Author Share Posted April 14, 2009 could loop it. Just make the one list item, and throw in the loop around it to generate the rest. My initial thoughts; I do not believe that would work with the current way I am doing things. There will always be a set number of list items (seven of them, one for each day of the week). The actual day of the week and day of the month are calculated based on one piece of information: today's date. $month = date(n); $year = date(Y); $today = date(j); I then calculate the date for the previous 3 and the following three days from that information. To calculate the current day of the week: (uppercase text to the left and top of each block) <?php $var = $today - 3; $day = mktime(0, 0, 0, $month, $var, $year); echo date("D",$day); ?> <?php $var = $today - 2; $day = mktime(0, 0, 0, $month, $var, $year); echo date("D",$day); ?> <?php $var = $today - 1; $day = mktime(0, 0, 0, $month, $var, $year); echo date("D",$day); ?> <?php $day = mktime(0, 0, 0, $month, $today, $year); echo date("D",$day); ?> <?php $var = $today + 1; $day = mktime(0, 0, 0, $month, $var, $year); echo date("D",$day); ?> <?php $var = $today + 2; $day = mktime(0, 0, 0, $month, $var, $year); echo date("D",$day); ?> <?php $var = $today + 3; $day = mktime(0, 0, 0, $month, $var, $year); echo date("D",$day); ?> To calculate the current day of the month: (larger number you see in the middle of the block) <?php echo $today - 3; ?> <?php echo $today - 2; ?> <?php echo $today - 1; ?> <?php echo $today; ?> <?php echo $today + 1; ?> <?php echo $today + 2; ?> <?php echo $today + 3; ?> Unless I am overlooking something. Essentially, I don't think I could create one list item and loop through it to fill in the information yet still apply individual conditions / code to each list item. Thanks. Link to comment https://forums.phpfreaks.com/topic/154133-code-cleanup/#findComment-810252 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.