473,406 Members | 2,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

foraech loop inside a for loop

Hello:

I got stuck again....

In my Hotel Reservation script all reservations are saved in a flat file which name is the room number. (example: Data/room1-101.dat).

Reservations are saved in the following manner.

Expand|Select|Wrap|Line Numbers
  1. 3
  2. John Smith|||||||||Day:,Eve:|25|4|2009|25|4|2009|11|30
  3. James Taylor|||||||||Day:,Eve:|26|4|2009|26|4|2009|11|30
  4. Peter Willam|||||||||Day:,Eve:|10|4|2009|20|4|2009|11|30
  5.  
This means there are three reservations:
First: starts 4/25/2009 ends same day (it is reservation for one day)
Second: starts 4/26/2009 ends same day (it is reservation for one day)
Third: starts 4/10/2009 and ends 4/20/2009 (reservation for 10 days).

I have a script that is supposed to show the reserved rooms in a table representing any given month named: Reserved_Rooms.cgi. Free rooms are green color. Reserved rooms are different colors.

My problem is that I cannot display all the resevations saved in Data/room1-101.dat . If you are able to open in a browser the script attached (Reserved_Rooms.cgi), and you look at the table it only shows the reservation in the forth line.

Room 106 has the same reservations as 101 but I shifted the order. Again it only shows the reservation on 4th line.

in Reserved_Rooms.cgi the first Blue column to the left shows all the room numbers followed to the right with column digits representing the day of the months (up to 31).

The coloring of rooms is determined by a snippet of code in Reserved_Rooms.cgi (lines 328 through 340) as follows:

Expand|Select|Wrap|Line Numbers
  1.      for($ca=0;$ca<=$Rooms_Reserved;$ca++)
  2. {
  3. ($Client_Name,$O1,$O2,$O3,$O4,$O5,$O6,$O7,$O8,$O9,$Start_Date,$Start_Month,$Start_Year,$End_Date,$End_Month,$End_Year,$Check_Out_Hour,$Check_Out_Min)=split (/\|/,$data[$ca]);    
  4. if($is == $sday) {$width ='30';}else{$width ='10';}
  5. if(($is < $sday)&&($is >= $Start_Date)&&($is <= $End_Date)&&($year == $Start_Year)){$bgcolor = '#9A9A9A';$Checkbox = '';}
  6. elsif(($is == $sday)&&($is >= $Start_Date)&&($is <= $End_Date)&&($year == $Start_Year)){$bgcolor = '#707070';$Checkbox = '';}
  7. elsif(($is > $sday)&&($is >= $Start_Date)&&($is <= $End_Date)&&($year == $Start_Year)){$bgcolor = '#FF0000';$Checkbox = '';}
  8. else{$bgcolor = '#00FF00';}
  9. if(($bgcolor eq '#00FF00')&&($is >= $sday))
  10. {$Checkbox = "<input type=checkbox name=\"RoomNum\" value=\"$is-$i-$rooms[$m-1]\">";}## (date-type-rumnum ###
  11. elsif($is < $sday){$Checkbox = '';}
  12.  
  13. }# END OF for($ca=0;$ca<=$Rooms_Reserved;$ca++)
I have tried inserting a foreach loop inside the for loop, in order to display each line of the flat file Data/room1-101.dat, in the following manner but it didnt work:

Expand|Select|Wrap|Line Numbers
  1.    for($ca=0;$ca<=$Rooms_Reserved;$ca++)
  2. {
  3. push(@All_Reservations, $data[$ca]);
  4. foreach $line (@All_Reservations){
  5. ($Client_Name,$O1,$O2,$O3,$O4,$O5,$O6,$O7,$O8,$O9,$Start_Date,$Start_Month,$Start_Year,$End_Date,$End_Month,$End_Year,$Check_Out_Hour,$Check_Out_Min)=split (/\|/,$line);    
  6. if($is == $sday) {$width ='30';}else{$width ='10';}
  7. if(($is < $sday)&&($is >= $Start_Date)&&($is <= $End_Date)&&($year == $Start_Year)){$bgcolor = '#9A9A9A';$Checkbox = '';}
  8. elsif(($is == $sday)&&($is >= $Start_Date)&&($is <= $End_Date)&&($year == $Start_Year)){$bgcolor = '#707070';$Checkbox = '';}
  9. elsif(($is > $sday)&&($is >= $Start_Date)&&($is <= $End_Date)&&($year == $Start_Year)){$bgcolor = '#FF0000';$Checkbox = '';}
  10. else{$bgcolor = '#00FF00';}
  11. if(($bgcolor eq '#00FF00')&&($is >= $sday))
  12. {$Checkbox = "<input type=checkbox name=\"RoomNum\" value=\"$is-$i-$rooms[$m-1]\">";}## (date-type-rumnum ###
  13. elsif($is < $sday){$Checkbox = '';}
  14. }# END OF foreach $line (@All_Reservations){
  15. }# END OF for($ca=0;$ca<=$Rooms_Reserved;$ca++)


The color meaning is:
Light gray, used room (any day prior to today)
Dark gray (room being used today)
Red, any reserved room not used yet (future reservation any date beyond today)
Green, any free room.

Hope you can straight me out... I want the script to display all reservations.
(Attached scripts in bundle Reserve.zip)
Thanx beforehand
VirtualWeb
Attached Files
File Type: zip Reserve.zip (10.1 KB, 126 views)
Apr 13 '09 #1
2 2388
KevinADC
4,059 Expert 2GB
Oh my goodness..... sorry mate, I'm not looking through that much code written without strict or even warnings. I hope to heaven that code is not being used on a real website, if it is, there is no way it will run for very long before crashing and burning. Sorry to be so negative sounding but you have a can of worms there.
Apr 14 '09 #2
Move code in the script Reserved_Rooms.cgi from line #341
Expand|Select|Wrap|Line Numbers
  1. print"<td bgcolor=$bgcolor width=$width><center><b>$is<br>$Checkbox$HR</center></td>";
to line #339, i.e. before line
Expand|Select|Wrap|Line Numbers
  1.  }# END OF for($ca=0;$ca<=$Rooms_Reserved;$ca++) 
WBR,
Dmitry Grasevitch
Apr 16 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: r rk | last post by:
I am trying to write a utility/query to get a report from a table. Below is the some values in the table: table name: dba_daily_resource_usage_v1...
8
by: ben | last post by:
i have a bit of code, that works absolutely fine as is, but seems over complicated/long winded. is there anyway to shorten/simplify it? the code is below. description of it: it's like strcpy in...
1
by: Jim P. | last post by:
I'm having trouble returning an object from an AsyncCallback called inside a threaded infinite loop. I'm working on a Peer2Peer app that uses an AsyncCallback to rerieve the data from the remote...
32
by: cj | last post by:
When I'm inside a do while loop sometimes it's necessary to jump out of the loop using exit do. I'm also used to being able to jump back and begin the loop again. Not sure which language my...
7
by: DaVinci | last post by:
I am writing a pong game.but met some problem. the ball function to control the scrolling ball, void ball(int starty,int startx) { int di ,i; int dj,j; di = 1; dj = 1; i = starty;
14
by: Michael Moreno | last post by:
Hello, Would you know what is best practice please between say: CODE 1: TimeSpan ts; for (i=0; i<1000; i++) {
9
by: somenath | last post by:
Hi All, I have doubt regarding how compiler understands about while loop. For example the bellow mentioned code produce the output as mentioned bellow. #include<stdio.h> int main(void) {
5
by: sgurukrupagmailcom | last post by:
Hi, I haven't come accross an elegant solution to a design problem that I show below. Have a look at the piece of code here: class Exc { Exc () { System.out.println ("Haribol"); }
1
by: JavaJon | last post by:
Hello, I'm Jon. I've recently picked up Java after using a "gimmick" programming language called GML ( Game Maker Language ). I've read a lot of tutorials and even a Java for Dummies *.pdf book....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.