TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   Date/Time Loop ... (http://www.talkphp.com/absolute-beginners/5834-date-time-loop.html)

pepelepew1962 04-03-2011 08:20 PM

Date/Time Loop ...
 
Hello:

I am trying to create an appointment table and am having problems. I have a loading facility that I need to create an appointment book for. The theory is simple, but where I am having problems is creating a loop for adding to the table. Basically I need a to create a form where I enter the start date, start time along with end date and end time. Let's say the facility loads every day and has hourly appointments starting at 0700 hrs and ends at 1800 hrs. I would like to enter the start date, let's say April 01, 2011 and end date of September 1, 2011. Loop and create records of each date with the hour. Can anyone help me with this please. I have included a sample of the output in my mysql table:


tblName02
04/01/2011 07:00:00
04/01/2011 08:00:00
04/01/2011 09:00:00
04/01/2011 10:00:00
04/01/2011 11:00:00
04/01/2011 12:00:00
04/01/2011 13:00:00
04/01/2011 14:00:00
04/01/2011 15:00:00
04/01/2011 16:00:00
04/01/2011 17:00:00
04/01/2011 18:00:00

04/02/2011 07:00:00
04/02/2011 08:00:00
...

adamdecaf 04-04-2011 02:58 PM

An idea:

PHP Code:

// Forward: This is an idea, and is incomplete.
date_default_timezone_set('UTC');

// If you take the unix time from the start.
// http://us3.php.net/manual/en/function.mktime.php
$start mktime(START);

// Calculate the number of seconds in a day
$day 60 60 24

// Find the unix timestamp for the end
$end mktime(END);

for (
$i $start$i <= $end$i += $day) {
   echo 
date("m/d/Y h:i:s"$i) . '\n';



maeltar 04-10-2011 11:07 AM

Quote:

Originally Posted by pepelepew1962 (Post 31858)
Hello:

I am trying to create an appointment table and am having problems. I have a loading facility that I need to create an appointment book for. The theory is simple, but where I am having problems is creating a loop for adding to the table. Basically I need a to create a form where I enter the start date, start time along with end date and end time. Let's say the facility loads every day and has hourly appointments starting at 0700 hrs and ends at 1800 hrs. I would like to enter the start date, let's say April 01, 2011 and end date of September 1, 2011. Loop and create records of each date with the hour. Can anyone help me with this please. I have included a sample of the output in my mysql table:


tblName02
04/01/2011 07:00:00
04/01/2011 08:00:00
04/01/2011 09:00:00
04/01/2011 10:00:00
04/01/2011 11:00:00
04/01/2011 12:00:00
04/01/2011 13:00:00
04/01/2011 14:00:00
04/01/2011 15:00:00
04/01/2011 16:00:00
04/01/2011 17:00:00
04/01/2011 18:00:00

04/02/2011 07:00:00
04/02/2011 08:00:00
...

Would an easier way to be use 2 tables or maybe 3..

tbl1
id | ddate
1 | 04/01/2011
2 | 04/02/2011
etc ....


tbl2
id | ttime
1 | 07:00:00
2 | 08:00:00
3 | 09:00:00
4 | 10:00:00
5 | 11:00:00
6 | 12:00:00
7 | 13:00:00
8 | 14:00:00
9 | 15:00:00
10 | 16:00:00
11 | 17:00:00
12 | 18:00:00

You can itterate through the tables to get the listings you want..

Now a third table

tbl3
id | id_ddate | id_ttime | details
1 | 1 | 4 | details of appt
etc...

so using sql grabbing the data you need should be a breeze..

maeltar 04-10-2011 11:50 AM

Maybe I should have read your post properly first :D

this may help using my method

PHP Code:

for ( $counter 0$counter <= 190$counter += 1)
    {
     
$next_day mktime(0,0,0,date("m"),date("d")+$counter,date("Y"));
    
$new_date date("Y-m-d"$next_day);
    
mysql_query("INSERT INTO ddate (id, ddate) VALUES('', '{$new_date}' ) ") or die(mysql_error());
    } 


maeltar 04-10-2011 12:08 PM

Ok, it's Sunday and am bored....

PHP Code:

$sql1 mysql_query("select * from ddate");
$sql2 mysql_query("select * from ttime"); 

while ( 
$row1 mysql_fetch_array($sql1) )
    {
    echo 
"<p>Date : " $row1[1] . "<br /><DIV style=\"margin-left:10%; margin-right:80%; border-style:double\">";
        while ( 
$row2 mysql_fetch_array($sql2) )
            {
            echo 
"Time : " $row2[1] . "<br />\n";
            }
    echo 
"</div></p>\n";
    
mysql_data_seek($sql2,0);        
    } 



All times are GMT. The time now is 10:22 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0