billy_111 Posted June 4, 2010 Share Posted June 4, 2010 Hey, I am using a calendar on this page: http://www.glofamily.com/glo/about-us/, which can be seen in the right panel. If you click on a day, it takes you to a page like so: http://www.glofamily.com/glo/general-courses/?day=2 June 2010 Now i want to be able to have the link to be like this: ?day=02 June 2010 so i need to change the way the links work on the calendar, i tried using number_format but had no luck. This is my code for the calendar, where do i need to change the code to achieve this? <div id="calendar" class="right"> <?php $date = (!isset($_GET['month']) && !isset($_GET['year'])) ? time() : strtotime($_GET['month'] . '/1/' . $_GET['year']); $day = date('d', $date) ; $month = date('m', $date) ; $year = date('Y', $date) ; $first_day = mktime(0,0,0,$month, 1, $year) ; $title = date('F', $first_day) ; $day_of_week = date('D', $first_day) ; switch($day_of_week){ case "Sun": $blank = 0; break; case "Mon": $blank = 1; break; case "Tue": $blank = 2; break; case "Wed": $blank = 3; break; case "Thu": $blank = 4; break; case "Fri": $blank = 5; break; case "Sat": $blank = 6; break; } $days_in_month = cal_days_in_month(0, $month, $year) ; ?> <div id="php-calendar" class="right"> <table> <?php if(isset($_GET['ID']) && isset($_GET['c'])){ echo "<tr><th colspan=7><a href=\"?ID=".$_GET['ID']."&c=".$_GET['c']."&month=". ($month - 1) . "&year=$year\"><<</a> $title $year <a href=\"?ID=".$_GET['ID']."&c=".$_GET['c']."&month=" . ($month + 1) . "&year=$year\">>></a></th></tr>"; } else { echo "<tr><th colspan=7><a href=\"?month=". ($month - 1) . "&year=$year\"><<</a> $title $year <a href=\"?month=" . ($month + 1) . "&year=$year\">>></a></th></tr>"; } ?> <tr><td width=42>S</td><td width=42>M</td><td width=42>T</td><td width=42>W</td><td width=42>T</td><td width=42>F</td><td width=42>S</td></tr> <?php $day_count = 1; echo "<tr>"; while ( $blank > 0 ) { echo "<td></td>"; $blank = $blank-1; $day_count++; } $day_num = 1; while ( $day_num <= $days_in_month ) { echo "<td> <a href='../general-courses/?day=$day_num $title $year'>$day_num</a></td>"; $day_num++; $day_count++; if ($day_count > 7) { echo "</tr><tr>"; $day_count = 1; } } while ( $day_count >1 && $day_count <=7 ) { echo "<td> </td>"; $day_count++; } ?> </table> </div> </div> Can you guys help me out? Thanks again Billy Quote Link to comment Share on other sites More sharing options...
micah1701 Posted June 4, 2010 Share Posted June 4, 2010 to turn 2 into 02 check out the str_pad function: http://us.php.net/manual/en/function.str-pad.php $month = 2; $month = str_pad($month,2,0,STR_PAD_LEFT); echo $month; // returns: 02 Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted June 4, 2010 Share Posted June 4, 2010 Or you could use sprintf <?php $month = 2; echo sprintf('%02d',$month); ?> Ken 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.