Re: [PHP] Time Loop

2008-09-30 Thread Jim Lucas
MDB wrote:
 Hello All, I am trying to figure out how to loop through 2 given times. 
 I have a start time and a end time and want to look through every X mins
 and add a radio button.  Below is my latest try, can someone please help
 me out?
 
 
  $endTime = 17:00:00;
  $currentTime=09:00:00;
 
  $num_intervals = floor(($endTime - $currentTime) / 30);
 
  echo (Num_INter: .$num_intervals./br);
 
  $buffer_time = $currentTime;
  for($i = 0; $i  $num_intervals; $i++)
  {
echo (tr);
echo (td.$currentTime./td);
 
foreach ($days as $day)
{
echo (td);
echo (input type='radio' name='dateTimeSelection'
 value=$day);
 
echo (/td);
}
 
 
$buffer_time += $interval;
echo (/tr);
  }
 
 
 
 ps  I was having problems with my news reader, this may be posted twice,
 if so. Sorry.
 
 TIA
 

Here is what I think you are looking for.

?php

# I am guessing that your $days array looks something like this.
$days = array('Sunday',
  'Monday',
  'Tuesday',
  'Wednesday',
  'Thursday',
  'Friday',
  'Saturday');

# Get todays information
$d = getdate();

$endTime = 17:00:00;
list($et_hr, $et_min, $et_sec) = explode(':', $endTime);
$unix_endTime = mktime($et_hr, $et_min, $et_sec,
   $d['mon'], $d['mday'], $d['year']);

$currentTime=09:00:00;
list($ct_hr, $ct_min, $ct_sec) = explode(':', $currentTime);
$unix_currentTime = mktime($ct_hr, $ct_min, $ct_sec,
   $d['mon'], $d['mday'], $d['year']);

$interval = 60;

# Calculate how many rows their should be
$num_intervals = floor(($unix_endTime - $unix_currentTime) / $interval);

echo 'Num_INter: ', $num_intervals, '/br';

echo 'formtable';

for ( $i=$unix_currentTime; $i = $unix_endTime; $i=($i+$interval) ) {
  echo 'tr', 'td', date('Y/m/d H:i:s', $i), '/td';

  foreach ($days AS $day) {
echo 'td',
 'input type=radio name=dateTimeSelection value=',
 $day,
 ' /',
 $day,
 '/td';
  }
  # Don't forget to reset the $days array
  # otherwise the array pointer is at the last index
  reset($days);
  echo '/tr';
}

echo '/table/form';

?

-- 
Jim Lucas

   Some men are born to greatness, some achieve greatness,
   and some have greatness thrust upon them.

Twelfth Night, Act II, Scene V
by William Shakespeare


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Time Loop

2008-09-30 Thread MDB

Thank you, I will try that out.

Robert Cummings [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]

On Mon, 2008-09-29 at 17:01 -0400, MDB wrote:
Hello All, I am trying to figure out how to loop through 2 given times. 
I
have a start time and a end time and want to look through every X mins 
and
add a radio button.  Below is my latest try, can someone please help me 
out?



  $endTime = 17:00:00;
  $currentTime=09:00:00;

  $num_intervals = floor(($endTime - $currentTime) / 30);


You should convert your times to minutes so you can use minute
intervals... the following was written directly into the email and so it
is UNTESTED:

?php

   $bits = explode( ':', $currentTime );
   $currentTime = $bits[0] * 60 + $bits[1];

   $bits = explode( ':', $endTime );
   $endTime = $bits[0] * 60 + $bits[1];

   $interval = 15; // minutes
   for( $i = $currentTime; $i = $endTime; $i += $interval )
   {
   $time = floor( $i / 60 ).':'.($i % 60).':00';
   }

?

Adapt to fit your needs.

Note: I used a time interval like you state in your above description (X
mins). But the code you submitted used appeared to use number of time
slices instead.

Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Time Loop

2008-09-29 Thread MDB
Hello All, I am trying to figure out how to loop through 2 given times.  I 
have a start time and a end time and want to look through every X mins and 
add a radio button.  Below is my latest try, can someone please help me out?



 $endTime = 17:00:00;
 $currentTime=09:00:00;

 $num_intervals = floor(($endTime - $currentTime) / 30);

 echo (Num_INter: .$num_intervals./br);

 $buffer_time = $currentTime;
 for($i = 0; $i  $num_intervals; $i++)
 {
   echo (tr);
   echo (td.$currentTime./td);

   foreach ($days as $day)
   {
   echo (td);
   echo (input type='radio' name='dateTimeSelection' 
value=$day);


   echo (/td);
   }


   $buffer_time += $interval;
   echo (/tr);
 }



ps  I was having problems with my news reader, this may be posted twice, if 
so. Sorry.


TIA 



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Time Loop

2008-09-29 Thread Robert Cummings
On Mon, 2008-09-29 at 17:01 -0400, MDB wrote:
 Hello All, I am trying to figure out how to loop through 2 given times.  I 
 have a start time and a end time and want to look through every X mins and 
 add a radio button.  Below is my latest try, can someone please help me out?
 
 
   $endTime = 17:00:00;
   $currentTime=09:00:00;
 
   $num_intervals = floor(($endTime - $currentTime) / 30);

You should convert your times to minutes so you can use minute
intervals... the following was written directly into the email and so it
is UNTESTED:

?php

$bits = explode( ':', $currentTime );
$currentTime = $bits[0] * 60 + $bits[1];

$bits = explode( ':', $endTime );
$endTime = $bits[0] * 60 + $bits[1];

$interval = 15; // minutes
for( $i = $currentTime; $i = $endTime; $i += $interval )
{
$time = floor( $i / 60 ).':'.($i % 60).':00';
}

?

Adapt to fit your needs.

Note: I used a time interval like you state in your above description (X
mins). But the code you submitted used appeared to use number of time
slices instead.

Cheers,
Rob.
-- 
http://www.interjinn.com
Application and Templating Framework for PHP


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php