Author |
Topic |
|
JJenson
Advanced Member
USA
2121 Posts |
Posted - 24 February 2008 : 18:50:26
|
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:
|
|
phy1729
Average Member
USA
589 Posts |
Posted - 24 February 2008 : 21:22:32
|
Are the columns a static length? |
|
|
JJenson
Advanced Member
USA
2121 Posts |
Posted - 24 February 2008 : 22:41:49
|
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. |
|
|
phy1729
Average Member
USA
589 Posts |
Posted - 24 February 2008 : 23:07:12
|
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 |
|
|
JJenson
Advanced Member
USA
2121 Posts |
Posted - 24 February 2008 : 23:11:08
|
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. |
|
|
JJenson
Advanced Member
USA
2121 Posts |
Posted - 24 February 2008 : 23:13:49
|
OK I got it to work. Will you explain why this works this way?
this is the code I used:
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 |
|
|
phy1729
Average Member
USA
589 Posts |
Posted - 24 February 2008 : 23:17:42
|
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
|
|
|
JJenson
Advanced Member
USA
2121 Posts |
Posted - 24 February 2008 : 23:21:20
|
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:
|
|
|
phy1729
Average Member
USA
589 Posts |
Posted - 24 February 2008 : 23:25:24
|
I don't know. |
|
|
JJenson
Advanced Member
USA
2121 Posts |
Posted - 24 February 2008 : 23:27:34
|
Alright thanks for the help |
|
|
JJenson
Advanced Member
USA
2121 Posts |
Posted - 24 February 2008 : 23:48:01
|
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. |
|
|
cripto9t
Average Member
USA
881 Posts |
Posted - 25 February 2008 : 08:43:39
|
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\-_ |
|
|
JJenson
Advanced Member
USA
2121 Posts |
Posted - 25 February 2008 : 08:55:09
|
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 |
|
|
muzishun
Senior Member
United States
1079 Posts |
Posted - 25 February 2008 : 13:16:13
|
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) |
|
|
JJenson
Advanced Member
USA
2121 Posts |
Posted - 25 February 2008 : 14:12:03
|
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 |
|
|
|
Topic |
|