Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 Displaying a List
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

JJenson
Advanced Member

USA
2121 Posts

Posted - 24 February 2008 :  18:50:26  Show Profile  Visit JJenson's Homepage
Ok so I made a database with 8 records in it I was able to get it to display like this:

1 2
3 4
5 6
7 8

I want to display it like this how would I go about doing it?

1 5
2 6
3 7
4 8

This is the code I am using to do the first:


<%
Dim m_DataLayer : Set m_DataLayer = New DataLayer
Dim SqlData

Sub DisplayColumns
For
Exit Sub
End Sub

%>

<table width="600" cellpadding="0" cellspacing="0" border="1" align="center">
<tr>

<%
SqlData = m_DataLayer.GetTheAvatar()

Dim Col1, COl2

Select Case(IsArray(SqlData))
Case True: For i = 0 to UBound(SqlData, 2)
Select Case(i mod 2)
Case 0: Col1 = Col1 & "<li>" & SqlData(0, i) & "</li>"
Case 1: Col2 = Col2 & "<li>" & SqlData(0, i) & "</li>"
End Select
Next
Case Else: Response.Write("Nothing")
End Select
%>
<td><%=Col1%></td>
<td><%=Col2%></td>
</tr>
</table>

<%
Set m_DataLayer = Nothing
%>

phy1729
Average Member

USA
589 Posts

Posted - 24 February 2008 :  21:22:32  Show Profile
Are the columns a static length?
Go to Top of Page

JJenson
Advanced Member

USA
2121 Posts

Posted - 24 February 2008 :  22:41:49  Show Profile  Visit JJenson's Homepage
No I basically want it to be dynamic to the point of something liek this:

First column would start like this

1
2

Then if a third is made it would look like this

1 3
2

then

1 3
2 4

And so forth all the way down.
Go to Top of Page

phy1729
Average Member

USA
589 Posts

Posted - 24 February 2008 :  23:07:12  Show Profile
Change

						Select Case(i mod 2)
							Case 0:	Col1 = Col1 & "<li>" & SqlData(0, i) & "</li>"
							Case 1:	Col2 = Col2 & "<li>" & SqlData(0, i) & "</li>"
						End Select

to

						Select Case(i%4)
							Case 0:	Col1 = Col1 & "<li>" & SqlData(0, i) & "</li>"
							Case 1:	Col1 = Col1 & "<li>" & SqlData(0, i) & "</li>"
							Case 2:	Col2 = Col2 & "<li>" & SqlData(0, i) & "</li>"
							Case 3:	Col2 = Col2 & "<li>" & SqlData(0, i) & "</li>"
						End Select

I think this is what you want.

Edited by - phy1729 on 24 February 2008 23:07:28
Go to Top of Page

JJenson
Advanced Member

USA
2121 Posts

Posted - 24 February 2008 :  23:11:08  Show Profile  Visit JJenson's Homepage
Very Close to what I need this displays:

1 3
2 4
5 7
6 8

Also I had to change the 1%4 to i mod 4 it said the % was an invalid character.
Go to Top of Page

JJenson
Advanced Member

USA
2121 Posts

Posted - 24 February 2008 :  23:13:49  Show Profile  Visit JJenson's Homepage
OK I got it to work. Will you explain why this works this way?

this is the code I used:


Select Case(i mod 8)
Case 0: Col1 = Col1 & "<li>" & SqlData(0, i) & "</li>"
Case 1: Col1 = Col1 & "<li>" & SqlData(0, i) & "</li>"
Case 2: Col1 = Col1 & "<li>" & SqlData(0, i) & "</li>"
Case 3: Col1 = Col1 & "<li>" & SqlData(0, i) & "</li>"
Case 4: Col2 = Col2 & "<li>" & SqlData(0, i) & "</li>"
Case 5: Col2 = Col2 & "<li>" & SqlData(0, i) & "</li>"
Case 6: Col2 = Col2 & "<li>" & SqlData(0, i) & "</li>"
Case 7: Col2 = Col2 & "<li>" & SqlData(0, i) & "</li>"
End Select


Second is there a better way to go about this?

Edit * NEvermind on why it works it makes perfect sense I just was being dumb. But I still want to know if there is a better way to go about this?


Edited by - JJenson on 24 February 2008 23:16:58
Go to Top of Page

phy1729
Average Member

USA
589 Posts

Posted - 24 February 2008 :  23:17:42  Show Profile
I suspect so try

if (i mod 8) < 5 then Col1 = Col1 & "<li>" & SqlData(0, i) & "</li>"
else Col2 = Col2 & "<li>" & SqlData(0, i) & "</li>"
end if
Go to Top of Page

JJenson
Advanced Member

USA
2121 Posts

Posted - 24 February 2008 :  23:21:20  Show Profile  Visit JJenson's Homepage
I am getting this error with that:

Expected 'Next'

/test/display.asp, line 40

else Col2 = Col2 & "<li>" & SqlData(0, i) & "</li>"

This is my code:

Select Case(IsArray(SqlData))
Case True: For i = 0 to UBound(SqlData, 2)
if (i mod 8) < 5 then Col1 = Col1 & "<li>" & SqlData(0, i) & "</li>"
else Col2 = Col2 & "<li>" & SqlData(0, i) & "</li>"
end if
Next
Case Else: Response.Write("Nothing")
End Select
Go to Top of Page

phy1729
Average Member

USA
589 Posts

Posted - 24 February 2008 :  23:25:24  Show Profile
I don't know.
Go to Top of Page

JJenson
Advanced Member

USA
2121 Posts

Posted - 24 February 2008 :  23:27:34  Show Profile  Visit JJenson's Homepage
Alright thanks for the help
Go to Top of Page

JJenson
Advanced Member

USA
2121 Posts

Posted - 24 February 2008 :  23:48:01  Show Profile  Visit JJenson's Homepage
Anyone else got an idea I would take it gladly

The reason I am figuring these things out is I have an interview tomorrow with a new company. They are looking to hire an entry level classic asp programmer and this is on their quiz in some form so just trying to cover everything I can.
Go to Top of Page

cripto9t
Average Member

USA
881 Posts

Posted - 25 February 2008 :  08:43:39  Show Profile
Untested but maybe you can see where I'm going with this.
If you want it to be dynamic you need to find the mid point
no matter what the number is.
output:
1 2

0r

1 7
2 8
3 9
4 10
5 11
6


<%	
Dim m_DataLayer : Set m_DataLayer = New DataLayer	
Dim SqlData			
%>
<table width="600" cellpadding="0" cellspacing="0" border="1" align="center">
  <tr> 
<%
SqlData = m_DataLayer.GetTheAvatar()

Dim iRecCnt,tmpRecCnt,iMidCnt,Col1, COl2

iRecCnt = uBound(SqlData,2)  'total rec count (0 based)

if isArray(SqlData) then
    tmpRecCnt = iRecCnt + 1      'increase by 1 so it is not 0 based
    isEven = tmpRecCnt Mod 2     '0 if even number, 1 if odd

    iMidCnt = tmpRecCnt/2               'find the halfway point by dividing by 2 
    iMidCnt = (cInt(iMidCnt) + isEven)  'if number is odd, the first col will be the longer col. if not they will be even 
    iMidCnt = iMidCnt - 1               'subtract 1 so it is 0 based again
else
    Response.Write("Not an array. Check sql")
    Response.End                        'Get out now before it throws an error
end if

 

For i = 0 to iRecCnt
    if i <= iMidCnt then
        Col1 = Col1 & "<li>" & SqlData(0, i) & "</li>"
    else
        Col2 = Col2 & "<li>" & SqlData(0, i) & "</li>"
    end if
Next

%>
    <td><%=Col1%></td>
    <td><%=Col2%></td>
  </tr>
</table>
<%
Set m_DataLayer = Nothing
%>

    _-/Cripto9t\-_
Go to Top of Page

JJenson
Advanced Member

USA
2121 Posts

Posted - 25 February 2008 :  08:55:09  Show Profile  Visit JJenson's Homepage
Thanks cripto that worked perfectly. Well now I just hope I can modify this to take care of multiple columns and rows together. I think if I can do this I might have a very good chance at the job

Thanks for the suggestions everyone
Go to Top of Page

muzishun
Senior Member

United States
1079 Posts

Posted - 25 February 2008 :  13:16:13  Show Profile  Visit muzishun's Homepage
Don't forget to post back here after the interview to let us know how it went.

Bill Parrott
Senior Web Programmer, University of Kansas
Co-Owner and Code Monkey, Eternal Second Designs (www.eternalsecond.com)
Personal Website (www.chimericdream.com)
Go to Top of Page

JJenson
Advanced Member

USA
2121 Posts

Posted - 25 February 2008 :  14:12:03  Show Profile  Visit JJenson's Homepage
I don't think it went well at all the test they had me do was way different than what I was told. You had to create a login script and validate it was a valid user then log them in then display all users and make their names clickable then from there then it takes you into their id only and displays all their info

I bombed horribly oh well guess I need alot mroe work
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.25 seconds. Powered By: Snitz Forums 2000 Version 3.4.07