Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

displaying continuous data from a twodimensional array 1

Status
Not open for further replies.

mmasuda

Technical User
Dec 28, 2004
35
US
I am trying display information from two related tables out of a database. After creating an inner join query, I use the following to display the information

MyArray = rsmastdetail.GetRows()
Const Mydegree = 19
dim vartemp

vartemp = 0

Response.Write("<p>")
For x = 0 To Ubound(MyArray,2)
If (vartemp <> MyArray(0,x)) then
vartemp = MyArray(0,x)
Response.Write("Id: " & MyArray(0,x) _
& "<br>Institution: " & MyArray(1,x) _
& "<br>Department 1: " & MyArray(2,x) _
& "<br>Department 2: " & MyArray(3,x)& "<br>Degree: " & MyArray(Mydegree, x))
Else
Response.Write(MyArray(Mydegree, x) & "<br>")
End If
Response.Write("</p><hr>")
Next

The problem is that many of the Institutions offer more than one degree. The "degrees" are not displayed continuously as it loops once and displays the degree once. Only if it goes into the else statement will the other degrees be displayed this caused to display a new paragraph. I have tried all I can think of but not found a solution on how to loop through the degrees to display them continously.

Here is an example on how they show up:
Id: 766
Institution: Oxnard College
Department 1:
Department 2:
Degree: AS in Addictive Disorders Studies
------------------------------------------------------------
Addictive Disorders Studies Certificate
------------------------------------------------------------
Addictive Disorders Studies in the Criminal Justice System Certificate

Thank you for any help and tips
MM
 
There are two ways you could handle the output of the degree.
1) (This is the one you have used) You could add a Response.Write of the degree to the top part of your if statement so that the first differant degree is shown (or in the cases of one degree, the one degree is shown)
or
2) You could break up your if statement and just use one output of the degree outside of the if statement

Personally I generally go with the second method. It would look something like:
Code:
Response.Write("<p>")
For x = 0 To Ubound(MyArray,2)
    '-- show the header info if ID has changed
    If (vartemp <> MyArray(0,x)) then
        vartemp = MyArray(0,x)
        Response.Write("Id: " & MyArray(0,x) _
        & "<br>Institution: " & MyArray(1,x) _
        & "<br>Department 1: " & MyArray(2,x) _
        & "<br>Department 2: " & MyArray(3,x) & "<br>"
    End If

    '-- always show the degree for this record
    Response.Write(MyArray(Mydegree, x) & "<br>")

    Response.Write("</p><hr>")    
Next

Now to your problem/question:
Your outputting your start paragraph tag outside the loop but your end paragraph tag inside the loop (along with the HR). If you truly want to encapsulate each institution section in a paragraph with only one HR after all of the degrees then you can modify the code above to only start a new paragraph when you start a new ID:
Code:
For x = 0 To Ubound(MyArray,2)
    '-- show the header info if ID has changed
    If (vartemp <> MyArray(0,x)) then
        vartemp = MyArray(0,x)
        '-- start a new paragraph for this new ID
        Response.Write "<p>"
        Response.Write("Id: " & MyArray(0,x) _
        ...

To finish the paragraph you would then need to output the end paragraph tag and HR when the next ID is going to be differant. Two choices here, you can either look ahead at the bottom of your loop, or you can use the existing if statement and do a further check to make sure this isn't the first record. The first option is fairly straightforward but requires a little more logic, the second solution is shorter, but a might be little harder to wrap your head around at first.

Adding the code to the end of the for loop would look something like:
Code:
        ...
        & "<br>Department 2: " & MyArray(3,x) & "<br>"
    End If

    '-- always show the degree for this record
    Response.Write(MyArray(Mydegree, x) & "<br>")

    '-- If this is the last record or next one is differant, end paragraph
    If UBound(MyArray,2) = x Then
        Response.Write "</p>"
    ElseIf MyArray(0,x + 1) <> vartemp Then
        Response.Write "</p><hr>"
    End if
Next

Or if you wanted to add it to the existing if statement then:
Code:
For x = 0 To Ubound(MyArray,2)
    '-- show the header info if ID has changed
    If (vartemp <> MyArray(0,x)) then
        vartemp = MyArray(0,x)
        '-- if this is not first record, end the previous paragraph
        If vartemp <> 0 Then Response.Write "</p><hr>"

        '-- start a new paragraph for this new ID
        Response.Write "<p>"
        Response.Write("Id: " & MyArray(0,x) _
        ...
   
   ...
   '-- always show the degree for this record
    Response.Write(MyArray(Mydegree, x) & "<br>")
Next

'-- if we read any records, finish last open paragraph
If vartemp <> 0 Then Response.Write "</p>"


Either of those solutions should work for you. Now to take the second one a step further, I would probably change my output a bit to use div's and CSS rather than paragraphs and an HR:
Code:
For x = 0 To Ubound(MyArray,2)
    '-- show the header info if ID has changed
    If (vartemp <> MyArray(0,x)) then
        vartemp = MyArray(0,x)
        '-- if this is not first record, end the previous paragraph
        If vartemp <> 0 Then Response.Write "</div>"

        '-- start a new paragraph for this new ID
        Response.Write "<div class=""idpara"">"
        Response.Write("Id: " & MyArray(0,x) _
        ...

   ...
Next
'-- if we read any records, finish last open paragraph
If vartemp <> 0 Then Response.Write "</div>"

This would allow me to add some CSS at the top of my page like so:
Code:
<html>
<head>
<style>
   .idpara{
      border-bottom: 1px solid #008800;
      margin-bottom: 5px;
   }
</syle>
...

This would allow you to make other modifications to the look and feel (such as font, etc) without having to rewrite portions of your code.

in any case, I know it was longwinded, but hopefully this helps,
-T

 
This worked beautifully!!!!
Thank you so much. You have also answered another question I had (though I didn't ask it! you must have read my mind [smile]). My next task was to figure how to use style sheet and bypass the "" situation.
Again Thank you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top