TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 04-03-2011, 08:20 PM   #1 (permalink)
The Wanderer
 
Join Date: Jan 2010
Posts: 12
Thanks: 0
pepelepew1962 is on a distinguished road
Default 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
...
pepelepew1962 is offline  
Reply With Quote
Old 04-04-2011, 02:58 PM   #2 (permalink)
The Addict
 
adamdecaf's Avatar
 
Join Date: May 2009
Posts: 287
Thanks: 5
adamdecaf is on a distinguished road
Default

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';

__________________
My Site
adamdecaf is offline  
Reply With Quote
The Following User Says Thank You to adamdecaf For This Useful Post:
mjwalsh (04-05-2011)
Old 04-10-2011, 11:07 AM   #3 (permalink)
The Acquainted
 
Join Date: Nov 2009
Location: nr Stratford-Upon-Avon
Posts: 136
Thanks: 3
maeltar is on a distinguished road
Default

Quote:
Originally Posted by pepelepew1962 View Post
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..
__________________
Thanks... Simon

Sex, Drugs & Linux Rules
Send a message via MSN to maeltar
maeltar is offline  
Reply With Quote
Old 04-10-2011, 11:50 AM   #4 (permalink)
The Acquainted
 
Join Date: Nov 2009
Location: nr Stratford-Upon-Avon
Posts: 136
Thanks: 3
maeltar is on a distinguished road
Default

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());
    } 
__________________
Thanks... Simon

Sex, Drugs & Linux Rules
Send a message via MSN to maeltar
maeltar is offline  
Reply With Quote
Old 04-10-2011, 12:08 PM   #5 (permalink)
The Acquainted
 
Join Date: Nov 2009
Location: nr Stratford-Upon-Avon
Posts: 136
Thanks: 3
maeltar is on a distinguished road
Default

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);        
    } 
__________________
Thanks... Simon

Sex, Drugs & Linux Rules
Send a message via MSN to maeltar
maeltar is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Nested while loop needed for this? gtifllm General 1 08-17-2009 07:50 PM
Horizontal nested loop problem Dracula General 3 06-05-2008 03:12 PM
Another quetion - Loop inside a loop Jmz General 1 05-30-2008 09:07 PM
Breaking out of a... not a loop. delayedinsanity Advanced PHP Programming 2 04-22-2008 06:30 PM
Best Way To Loop In A Table? StevenF Absolute Beginners 16 03-14-2008 04:26 PM


All times are GMT. The time now is 12:42 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design