2 Loops (one insidethe other) - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

2 Loops (one insidethe other)

Hello,
I know my problem is long and twisty but I will try to simplify it as much as I can and in advance I appreciate any try for help

A part of my program lets the user:

1- sechadules activities for the year i.e state the activity and its date
2- Edits the information of the activites that has been sechadulaed before as he may wants to change the date or the activity name of an activity that has been previously inserted before.

Steps of the part 2 of the program:

First Step:

I let the user selects the activity or activities that he/she wants to edit
Second Step:

The activity or the activites along with their dates that he has selected appears to him on the screen with editable inputboxes to edit ----------(denote code written in this page by page 1)

Thirs Step:
Here comes the PBROBLEM. Now I want to put his/her updates in action, I want to be able to identify the date along with its selected activity to be able to update this specific activity----------(denote code written in this page by page 2)

The Rule is:
Rule 2: He/She may edit information of more than one date.
Rule 1: With each date there may be one or more activites.

Tables:

I work with 2 tables
First Table: ActDates
First field: (ActDateId, AutoNumber) ----> Id identifies the date
Second Field (ActDate,Date) -----> date itself
Second Table: ActivitesPerDay
First Field: (Id,Int) ------>Id identifies the activity along with its dates
Second Field: (ActDateId, Number) -----> date id
Third Field: (Activity,Text) ------>Activity name

My Code in page 1:

Sql ="Select * From ActDates , ActivitesPerDay Where ActDates.ActDateId =

ActivitesPerDay.ActDateId and (ActDates.ActDate > #"&DFVar&"# or

ActDates.ActDate < #"&DTVar&"# )"
Set Rs = Conn.Execute (Sql)


'Displaying results of the sql statement

If Rs.eof = 0 Then
Do While Not Rs.Eof
ADate = Rs("ActDateId")
DateVar = Rs("ActDate")
Ac_ID = Rs("Id")
Ac_Name = Rs("Activity")




 


Date


" >
" Name ="hidd_Date">


" Name ="hidd_DId">

Rs.MoveNext
Loop%>



My Code in page 2: (Update is to be put in action by this code)

I = 1
For Each Item in Request.Form("hidd_Date")
response.write "Date id is "&item%>
<%
response.write "Date is "&Request.Form("Txt_Date")(i)%>
<%
response.write "Sequence of Date is "&i%>


If Not Item = "" Then
X = 1
For Each XItem in Request.Form("hidd_DId")
response.write "Activity Id is"&Xitem%>
<%
response.write "Activity is"&Request.Form("Txt_Activity")(x)%>
<%
response.write "sequence of activity is"&X%>


' Here I do the update code

X = X + 1
Next
End IF
I = I + 1
Next

PROBLEM with Code:

Case:
Suppose the user selects to edit 2 dates, under the first date there are 2 activities and under the second date there is 1 activity.

Result: (Result of response.write,s of the code )

First date:
Date id is 289
Date is 11/11/2003
Sequence of Date is 1
Activities under this date:
First Activity:
Activity Id is117
Activity is birthdate
sequence of activity is1
Second activity
Activity Id is120
Activity isbirthdate
sequence of activity is2
Third Activity:
Activity Id is123
Activity is birthdate
sequence of activity is 3

Second Date:
Date id is 292
Date is 12/08/2003
Sequence of Date is 2
Activities under this date
First Activity:
Activity Id is117
Activity is birthdate
sequence of activity is1
Second activity
Activity Id is120
Activity isbirthdate
sequence of activity is2
Third Activity:
Activity Id is123
Activity is birthdate
sequence of activity is 3

Notice:

Under the first date, 3 activities are displayed instead of two
Under the second date, 3 activities are displayed instead of one

Cause of the problem:

In my code I loop through the selected dates by the user to update ( This is fine . He selected 2 dates and I Loop for 2 dates) and inside the loop of each date I loop for its

activites selected by the user. Here emerges the PROBLEM, the loop is done for ALL activities under ALL dates and Not Limited to the activities under the specified date this

is because:
In page 1 in which the code, all hidden input boxes of ALL acitivites for all dates are given the same name

The code line: " Name ="hidd_DId">

This line makes a hidden input box for all activites under all the dates with the same name "hidd_DId" to store the activity id which is "Ac_ID"

In page 2 in which I identify the acivites along with their dates which are selected by the user to edit

The code line : For Each XItem in Request.Form("hidd_DId")
This lines loops through the activities by their ids which are given by XItem

Solution:

I think solution lies in the correction of the way of looping trough the activities of EACH date -------The code line : For Each XItem in Request.Form("hidd_DId")

or

The solution lies in the correction of naming the hidden input box which passes the activity page from page1 to page 2

Thanks very much for effort of reading my problem and I will be very thankfull for any try to help.

Rasha, Egypt




Comments

  • FlakesFlakes Posts: 642Member
    : Hello,
    : I know my problem is long and twisty but I will try to simplify it as much as I can and in advance I appreciate any try for help
    :
    : A part of my program lets the user:
    :
    : 1- sechadules activities for the year i.e state the activity and its date
    : 2- Edits the information of the activites that has been sechadulaed before as he may wants to change the date or the activity name of an activity that has been previously inserted before.
    :
    : Steps of the part 2 of the program:
    :
    : First Step:
    :
    : I let the user selects the activity or activities that he/she wants to edit
    : Second Step:
    :
    : The activity or the activites along with their dates that he has selected appears to him on the screen with editable inputboxes to edit ----------(denote code written in this page by page 1)
    :
    : Thirs Step:
    : Here comes the PBROBLEM. Now I want to put his/her updates in action, I want to be able to identify the date along with its selected activity to be able to update this specific activity----------(denote code written in this page by page 2)
    :
    : The Rule is:
    : Rule 2: He/She may edit information of more than one date.
    : Rule 1: With each date there may be one or more activites.
    :
    : Tables:
    :
    : I work with 2 tables
    : First Table: ActDates
    : First field: (ActDateId, AutoNumber) ----> Id identifies the date
    : Second Field (ActDate,Date) -----> date itself
    : Second Table: ActivitesPerDay
    : First Field: (Id,Int) ------>Id identifies the activity along with its dates
    : Second Field: (ActDateId, Number) -----> date id
    : Third Field: (Activity,Text) ------>Activity name
    :
    : My Code in page 1:
    :
    : Sql ="Select * From ActDates , ActivitesPerDay Where ActDates.ActDateId =
    :
    : ActivitesPerDay.ActDateId and (ActDates.ActDate > #"&DFVar&"# or
    :
    : ActDates.ActDate < #"&DTVar&"# )"
    : Set Rs = Conn.Execute (Sql)
    :
    :
    : 'Displaying results of the sql statement
    :
    : If Rs.eof = 0 Then
    : Do While Not Rs.Eof
    : ADate = Rs("ActDateId")
    : DateVar = Rs("ActDate")
    : Ac_ID = Rs("Id")
    : Ac_Name = Rs("Activity")
    :
    :
    :
    :
    :  
    :
    :
    : Date
    :
    :
    : " >
    : " Name ="hidd_Date">
    :
    :
    : " Name ="hidd_DId">
    :
    : Rs.MoveNext
    : Loop%>
    :
    :
    :
    : My Code in page 2: (Update is to be put in action by this code)
    :
    : I = 1
    : For Each Item in Request.Form("hidd_Date")
    : response.write "Date id is "&item%><%
    : response.write "Date is "&Request.Form("Txt_Date")(i)%><%
    : response.write "Sequence of Date is "&i%>
    :
    : If Not Item = "" Then
    : X = 1
    : For Each XItem in Request.Form("hidd_DId")
    : response.write "Activity Id is"&Xitem%><%
    : response.write "Activity is"&Request.Form("Txt_Activity")(x)%><%
    : response.write "sequence of activity is"&X%>
    :
    : ' Here I do the update code
    :
    : X = X + 1
    : Next
    : End IF
    : I = I + 1
    : Next
    :
    : PROBLEM with Code:
    :
    : Case:
    : Suppose the user selects to edit 2 dates, under the first date there are 2 activities and under the second date there is 1 activity.
    :
    : Result: (Result of response.write,s of the code )
    :
    : First date:
    : Date id is 289
    : Date is 11/11/2003
    : Sequence of Date is 1
    : Activities under this date:
    : First Activity:
    : Activity Id is117
    : Activity is birthdate
    : sequence of activity is1
    : Second activity
    : Activity Id is120
    : Activity isbirthdate
    : sequence of activity is2
    : Third Activity:
    : Activity Id is123
    : Activity is birthdate
    : sequence of activity is 3
    :
    : Second Date:
    : Date id is 292
    : Date is 12/08/2003
    : Sequence of Date is 2
    : Activities under this date
    : First Activity:
    : Activity Id is117
    : Activity is birthdate
    : sequence of activity is1
    : Second activity
    : Activity Id is120
    : Activity isbirthdate
    : sequence of activity is2
    : Third Activity:
    : Activity Id is123
    : Activity is birthdate
    : sequence of activity is 3
    :
    : Notice:
    :
    : Under the first date, 3 activities are displayed instead of two
    : Under the second date, 3 activities are displayed instead of one
    :
    : Cause of the problem:
    :
    : In my code I loop through the selected dates by the user to update ( This is fine . He selected 2 dates and I Loop for 2 dates) and inside the loop of each date I loop for its
    :
    : activites selected by the user. Here emerges the PROBLEM, the loop is done for ALL activities under ALL dates and Not Limited to the activities under the specified date this
    :
    : is because:
    : In page 1 in which the code, all hidden input boxes of ALL acitivites for all dates are given the same name
    :
    : The code line: " Name ="hidd_DId">
    :
    : This line makes a hidden input box for all activites under all the dates with the same name "hidd_DId" to store the activity id which is "Ac_ID"
    :
    : In page 2 in which I identify the acivites along with their dates which are selected by the user to edit
    :
    : The code line : For Each XItem in Request.Form("hidd_DId")
    : This lines loops through the activities by their ids which are given by XItem
    :
    : Solution:
    :
    : I think solution lies in the correction of the way of looping trough the activities of EACH date -------The code line : For Each XItem in Request.Form("hidd_DId")
    :
    : or
    :
    : The solution lies in the correction of naming the hidden input box which passes the activity page from page1 to page 2
    :
    : Thanks very much for effort of reading my problem and I will be very thankfull for any try to help.
    :
    : Rasha, Egypt
    :
    :
    :
    :
    :


    There is one way to bypass all the looping and updations .
    1.Select the activities and show.
    2. Delete all the selected values from the activity table which were
    selected.
    3.After the user edits the activities,Insert *ALL* the values into the activity table,irrespective of whether it has been changed or not.

    OK,your activity ID will change ,but that's just used to keep track internally so can't see it causing any problems.

    Also,do you really need a table just to keep the dates .Seems to me that much of normalization isn't reqd. ,but it's just my thought.

    Just another way to do it.
Sign In or Register to comment.