Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Loop with time

Posted on 2001-06-11
13
Medium Priority
?
268 Views
Last Modified: 2013-12-24
hai, I need a loop function that use "time" as a counter.
eg. it will show as follow:

start from 10:00
10:00
10:30
11:00
11:30
...
until 20:00

how to make this function??

i have an example, but cannot work:

<cfset timeform = CreateTime(10,00,00)>
<cfset time= #TimeFormat(timeform, 'hh:mm')#>
<CFLOOP CONDITION="time less than or equal to '20:00'">
<cfoutput>
<tr>
<th>#time#</th>
</tr>
</cfoutput>
<cfset addedvar =#TimeFormat(dateadd('n',30,time), 'hh:mm')#>
<cfset time = addedvar>
</cfloop>
0
Comment
Question by:J2J
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
13 Comments
 
LVL 4

Expert Comment

by:CF_Spike
ID: 6177620
I'm not sure why you would want to do this. You will be absolutely killing the machine that the script runs on as it will be permanently using all available processor cycles to evaluate the loop.

If you can give us some more information about why you need this we can probably suggest a better strategy.

Spike
0
 

Author Comment

by:J2J
ID: 6178022
i see. so that's why my program run very slow and i say very very slow...

actually, i used this is for the purpose of matching time.
since i have three query to go for. each query has time variable.

i need the loop to cover at the outer, and the three query inside it.
if the time inside the query match the time of the loop,
it will display the data.

i have an example using number as variable (time change to num), and it work fine.
but when i intend to use time variable, the system goes very slow...

any suggestion for my problem?



0
 

Author Comment

by:J2J
ID: 6178051
here is the source code of my example:

<html>
<head>     <title>Untitled</title></head>

<body>testing preview
<cfquery name="testing1" datasource="DB">
 select * from testing where room = 'A'
</cfquery>

<table>
<tr> <th>TIME</th> <th>ROOM</th></tr>

<CFLOOP INDEX="Count"  FROM="1"  TO="20"  STEP="+1">
<tr>
<cfoutput>
   <th>#Count#</th>
</cfoutput>
     
<cfoutput query="testing1">
 <cfif (testing1.time eq Count)>
       <th>#testing1.name#</th>
 </cfif>
</cfoutput>
</tr>
</cfloop>
</table>

</body>
</html>
0
Plesk WordPress Toolkit

Plesk's WordPress Toolkit allows server administrators, resellers and customers to manage their WordPress instances, enabling a variety of development workflows for WordPress admins of all skill levels, from beginners to pros.

See why 2/3 of Plesk servers use it.

 
LVL 4

Expert Comment

by:CF_Spike
ID: 6178054
I sort of understand what you are doing, but can you post the code for the page with the queries so I can get a clearer idea of exactly what you are trying to do.

Spike
0
 

Author Comment

by:J2J
ID: 6178071
another two query is the same as testing1, just another testing2, testing3
and they are also put inside the loop.
0
 
LVL 4

Expert Comment

by:CF_Spike
ID: 6178107
um...

So where do you need to use the loop you originally asked about?

Also, there is only 1 query in this code, you mentioned that you have 3. Where are the others?

<CFLOOP CONDITION="time less than or equal to '20:00'">

Are you trying to only display data up until the current time?

Can you post the code that is causing the server to slow down, as the example doesn't really show me why you want to use the time variable.

Spike
0
 

Author Comment

by:J2J
ID: 6179485
let's make it simple.
the source code for my example is already posted, the only different is the other two
query testing2 and testing3 is quite the same, only different in condition.

as u can see, the following loop has been used for looping in the example:

   <CFLOOP INDEX="Count"  FROM="1"  TO="20"  STEP="+1">

but it can't work for the "time", so i decided to change it into:

   <CFLOOP CONDITION="time less than or equal to '20:00'">

but it cause the system run slow...

for testing purpose, i wish the output could be like this:

10:00  abc
10:30  
11:00  cde
11:30  
12:00
...until 20:00
the only query that match the time will be display at specific row.
  sample of query: abc's time is 10:00, cde's time is 11:00
0
 
LVL 4

Expert Comment

by:CF_Spike
ID: 6179596
ok, So if I understand you correctly you are saying that you only want the display to show times, not that it should be created incrementally as time gets to each half hour segment.

One way of doing that is as follows:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
     <title>Untitled</title>
</head>

<body>

<CFOUTPUT>

     <CFLOOP FROM="10" TO="20" INDEX="i">
     
          #TimeFormat(CreateTime(i,0,0),"HH:mm")#
         
          <BR>
         
          <CFIF i LT 20>
               
               #TimeFormat(CreateTime(i,30,0),"HH:mm")#<BR>
         
          </CFIF>
         
     </CFLOOP>

</CFOUTPUT>

</body>
</html>

This only displays the times. It doesn't do anything with the query results.

Spike
0
 

Author Comment

by:J2J
ID: 6179797
well, that's only a little part of what i meant.
true that i need a column at leftside to display the time,
but not forget that i also need a counter, eg "time".
i think in ur coding that "i" can be function like "time"

another problem is the query timeformat,
inside the Access db is "10:00"
but after the query, it display "1899-12-30 10:00:00"
how to solve this? if not, it won't match with the "i"


thank you.
0
 
LVL 4

Expert Comment

by:CF_Spike
ID: 6180894
The data will display as 10:00 in Access because Access is being _helpful_. The field is actually a datetime field. you can use DateCompare() to compare dates. If you want to construct a date from the i in the loop you can do the following:

<CFSET thisTime = CreateDateTime(0,0,0,i,0,0)>

And for the half hours:

<CFSET thisTime = CreateDateTime(0,0,0,i,30,0)>

You could then use DateCompare as follows:

<CFOUTPUT Query="testing1">
<CFIF DateCompare(thisTime,testing1.time,'h') EQ 0>
#testing1.somecolumn#
</CFIF>
</CFOUTPUT>

Spike
0
 

Author Comment

by:J2J
ID: 6197492
Almost completed, but still one problem:

source code:
<CFLOOP from="10" to="20" index="i">
  <CFSET thisTime1 = CreateDateTime(1899,12,30,i,0,0)>
  <CFSET thisTime2 = CreateDateTime(1899,12,30,i,30,0)>

  <cfoutput>
    <tr><th>#TimeFormat(thisTime1,"HH:mm")#<BR></th>
    <CFIF i LT 20>
      <tr><th>#TimeFormat(thisTime2,"HH:mm")#</th><BR>
    </CFIF>
  </cfoutput>
               
  <CFOUTPUT Query="VIEWApp1">
    <CFIF DateCompare(thisTime1,VIEWApp1.time_start,'h') EQ 0>
      <th>#VIEWApp1.cust_id#</th>
         
    <cfelseif DateCompare(thisTime2,VIEWApp1.time_start,'h') EQ 0>
      <th>#VIEWApp1.cust_id#</th>
    </CFIF>
  </CFOUTPUT>

  </tr>
</cfloop>

The result is : column correct, but row is wrong

Expected result:

10:00 abc
10:30
11:00

Actual result:
10:00
10:30 abc
11:00

which means that everything "drop a row"
     if 10:00 then show at 10:30 row(wrong)
     if 11:00 then show at 11:30 row(wrong)

     but if 10:30, it show at the correct row
     why this happen?
0
 

Accepted Solution

by:
JYnet earned 140 total points
ID: 6205935
in your case, using two variable is inefficient,
use one variable is more likely to be useful.
the following code might be suitable:

<CFSET thisTime1 = CreateDateTime(0,0,0,10,0,0)>
<CFLOOP CONDITION="thisTime1 LT CreateDateTime(0,0,0,20,30,0)">


  here is the loop body...


<CFSET thisTime1=dateadd('n',30,thisTime1)>
</cfloop>

also, not to forget to change <CFIF DateCompare(thisTime1,VIEWApp1.time_start,'h') EQ 0>
to <CFIF DateCompare(thisTime1,VIEWApp1.time_start,'n') EQ 0>
because the time need to match until minute.

hope this will help.
0
 

Author Comment

by:J2J
ID: 6209083
i think it does work. thanks!
0

Featured Post

Simplify Your Workload with One Tool

How do you combat today’s intelligent hacker while managing multiple domains and platforms? By simplifying your workload with one tool. With Lunarpages hosting through Plesk Onyx, you can:

Automate SSL generation and installation with two clicks
Experience total server control

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
What You Need to Know when Searching for a Webhost Provider
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question