tekrscom Posted June 9, 2007 Share Posted June 9, 2007 Hi, could someone please give me a boost in the right direction with this... When a user logs on, he should have a drop down selection box of week ending dates that would include any week ending dates that he hasn’t completed time for, only going back as far to a specified date and then also the current week he is within and up to 1 week forward. The week ending dates should always be on a Sunday. The table I have is as follows; CREATE TABLE `techs_pay_weeks` ( `tech_pay_week_id` int(11) NOT NULL auto_increment, `tech_pay_week_ending_date` date NOT NULL default '0000-00-00', `tech_id` int(11) NOT NULL default '0', `tech_pay_week_hours` float NOT NULL default '0', `tech_pay_week_amt` float NOT NULL default '0', `tech_pay_week_approved` tinyint(4) NOT NULL default '0', PRIMARY KEY (`tech_pay_week_id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; The tech_id is held as a $_SESSION[userid] when he logs in. I understand how to advance a date, but not from a dynamic date that should always fall on a Sunday, and a current Sunday at that. Link to comment https://forums.phpfreaks.com/topic/54880-solved-week-ending-dates/ Share on other sites More sharing options...
paul2463 Posted June 9, 2007 Share Posted June 9, 2007 try this <?php $last = strtotime("last Sunday"); $sunday = date("D M j Y", $last); echo $sunday; // as of today (sat Jun 9 2007) prints out Sun Jun 3 2007 echo "<BR>"; for ($i = 1; $i <52 ;$i++) { $sunarray[] = date("D M j Y", $last); $last = strtotime("+1 Week", $last); } print_r($sunarray); //prints out all the Sundays for the next year ?> Link to comment https://forums.phpfreaks.com/topic/54880-solved-week-ending-dates/#findComment-271452 Share on other sites More sharing options...
tekrscom Posted June 9, 2007 Author Share Posted June 9, 2007 I took that code and attempted to make it work for what I need, but instead of it filling my drop down box with the date, e.g. Sun Jun 3 2007 & Sun Jun 10 2007 , it filled it with 0 & 1 ... Here's what I did with the code... <?php $last = strtotime("last Sunday"); $sunday = date("D M j Y", $last); for ($i = 1; $i < 3 ;$i++) { $sunarray[] = date("D M j Y", $last); $last = strtotime("+1 Week", $last); } echo '<select name="week_ending_date">'; foreach($sunarray as $sunarray=>$last) { echo '<option value="', $sunarray, '">', $sunarray, '</option>'; } echo '</select>'; ?> I know I'm doing something wrong with the the array and the loop, I just don't know what... Link to comment https://forums.phpfreaks.com/topic/54880-solved-week-ending-dates/#findComment-271500 Share on other sites More sharing options...
paul2463 Posted June 9, 2007 Share Posted June 9, 2007 yes indeed, you have put the variable $last in there when it is not required, try this <?php $last = strtotime("last Sunday"); // I have removed the $sunday line because it is not needed for your code for ($i = 1; $i < 3 ;$i++) { $sunarray[] = date("D M j Y", $last); $last = strtotime("+1 Week", $last); } echo '<select name="week_ending_date">'; foreach($sunarray as $var) { echo '<option value="', $var, '">', $var, '</option>'; } echo '</select>'; ?> because you put the key value in the foreach loop it did what you asked and gave you the key number. Link to comment https://forums.phpfreaks.com/topic/54880-solved-week-ending-dates/#findComment-271526 Share on other sites More sharing options...
tekrscom Posted June 9, 2007 Author Share Posted June 9, 2007 Thank you very much for your help Paul, it is muchly appreciated... Link to comment https://forums.phpfreaks.com/topic/54880-solved-week-ending-dates/#findComment-271528 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.