PDA

View Full Version : ASP 3 Dim Array Prob


AnthonyP
11-28-2004, 02:03 PM
hi everyone,

Been a while since I been last here, but it's really nice to be back. :) Anyways... here is the situation. I have a script that displays the information of the people that enter my personal site. The script is run on an Access DB.

So I can explain the prople more clearly, here are some of the features of the script and how it works:

When a user logs into the site for the first time, a cookie is created ON the login script itself and then that user is marked as a known user. For example, this is a very small personal site, so only family and close friends use it. The DB is given the following info:

DATE
USER
(CLIENT ID)
BROWSER
TAG (must be set manually)
IP
CREATE (ONLY a value "yes" is eneterd when first cookie is created)
..and some other few tables.

The three most important sections are the CLIENT ID, TAG and CREATE. The CLIENT ID is the unique random number ID that the user gets the first time they log on. That ID will be used to identify that user every time they log in after that. TAG is a not I can manually enter to the DB to describe the record. For example, since I always use the same browser and thus always the same CLIENT ID, I gae myself a TAG called "ME, MSIE Home Comp), so when I look in the log, I should be able to check which computer I used to log in on a later date, for example. CREATE sets a value "yes" into the database when the cookie is created for the first time. Everyother time, when the cookie is reused, no data is entered here.

The problem with the script is that I am using some code I got help with from putts a while ago, and this code allows me to split up the results of the DB that get displayed in the table into pages. Because of this process, another important process gets interrupted.

That important proces has to do with TAG. On the final page, in the row for each record with "yes" in the CREATE field, there is a link to clikc on that allows me to add the TAG data for that CLIENT ID. So then, when the script reads the TAG data, it puts this into a 3 dim array that also stores the corresponding CLIENT ID. So everytime that specific CLIENT ID appears in the future, the script will also write the relevant TAG for it. This is done with a simple for next loop.

Now, if each page displays for example 10 listings, and the CREATE is not among those 10. Then the TAG information is not in the array because the array reads only those 10. What I need to do is get the script to read ALL the values to find the matches. Also, since the script works from top to bottom through the DB, I can't display the records in descending order because then the repeat logins get recorded before the initial CREATE, so they dont get listed into the array. So i end up having to use default ascending order which makes all the latest records go to the last page.

WHAT I need to do right now is get the script to display all my data in descending order where the latest entries in the DB are at the top first page and I need the script to be able to read all the create tags first, then have the values in an array with the CLIENT ID, so that all the repeat logins will have access to that array to dsplay the right TAGs in the right CLIENT IDs.

I hope this explanation isnt confusing! lol.. Any help at all will be greatly appriciated! Thanks in advance guys! If you ca't help me, I still appriciate you takign the time to read this far.. :) Thanks

Anthony

P.S. I will paste the code in another post! Message too long error! :P

AnthonyP
11-28-2004, 02:05 PM
HERE IS THE CODE:


<!--#include file="../_data/variables.asp"-->
<!--#include file="../_data/interface/html/core.head.asp"-->




<%
IF NOT Request("Tagset") = "" OR isNULL(Request("Tagset")) then
setTag()
End IF

IF NOT Request("Tagval") = "" OR isNULL(Request("Tagval")) then
saveTag()
End IF
%>



<form action="log.asp" name="logger" id="logger">
<b>Show Lines:</b>
<input type="text" name="show" value="<%= request("show") %>" size="20" style="font-size: 10px; font-family: Verdana; border: 1px solid #000000">
<input type="submit" name="submit" value="set" style="font-size: 10px; font-family: Verdana; border: 1px solid #000000">
<input type="hidden" name="start" value="<%= Request("start") %>">
</form>

<table width="100%" height="1" border="1" cellspacing="0" cellpadding="0" align="left" bordercolor="#000000" bgcolor="#FFFFEA" style="border-collapse: collapse">
<tr>
<td width="130" height="1" align="left" valign="top" nowrap bgcolor="#CCCCFF"><b>Time</b></td>
<td width="100" height="1" align="left" valign="top" nowrap bgcolor="#CCCCFF"><b>User</b></td>
<td width="200" height="1" align="left" valign="top" nowrap bgcolor="#CCCCFF"><b>Tag</b></td>
<td width="300" height="1" align="left" valign="top" nowrap bgcolor="#CCCCFF"><b>Client </b> </td>
<td width="100" height="1" align="left" valign="top" nowrap bgcolor="#CCCCFF"><b>IP</b></td>
<td width="550" height="1" align="left" valign="top" nowrap bgcolor="#CCCCFF"><b>Browser</b></td>
<td width="100" height="1" align="left" valign="top" nowrap bgcolor="#CCCCFF"><b>Language</b></td>
<td width="300" height="1" align="left" valign="top" nowrap bgcolor="#CCCCFF"><b>Referrer</b></td>
</tr>


<%
'***** DB CONNECTION ********************************************************************

Dim adoCon
Dim rs
Dim strSQL

Set adoCon = Server.CreateObject("ADODB.Connection")
adoCon.Open recdb
strSQL = "SELECT * FROM log" ' ORDER BY ID DESC (Removed)
set rs = adoCon.execute(strSQL)

'****************************************************************************************
%>



<%
'*************************************************************************************************** **

'****************
if request("start") = "" then
intStart = 0
else
intStart = cint(request("start"))
end if
'****************

'****************
If request("show") = "" then
postsPerPage = 25
else
postsPerPage = request("show")
end if
'****************

intPageEnd = intStart + postsPerPage

'****************
if not(rs.eof) then
blnExists = true
arrTable = rs.getRows
If intPageEnd > ubound(arrTable,2) then
intRSEnd = ubound(arrTable,2)
else
intRSEnd = intPageEnd-1
end if
else
blnExists = false
end if
'****************

'****************
if blnExists then
Dim overSize
overSize = 99999
Dim count
Dim arrTags(3,99999)
count = 0
for i=intStart to intRSEnd
showPost()
next

intCrntPage = intStart/postsPerPage

for i=0 to ubound(arrTable,2)/postsPerPage
if i<>intCrntPage then
response.write("<a href='log.asp?show=" & postsPerPage & "&start=" & i*postsPerPage & "'>" & i+1 & "</a> | ")
else
response.write("<B>" & i+1 & "</B> | ")
end if
next
end if
'****************

'Close Database
rs.close
set rs = nothing
adoCon.close
set adoCon = nothing
'*************************************************************************************************** **
%>

</table>





<%
Sub showPost()
%>

<%
'*****************************
'MAX OVERFLOW PROTECTION
If arrTable(0,i) => overSize then
Response.write "<strong><font size=""2"" color=""#FF0000"">ERROR! Database too big!</font></strong>"
Response.End
End if
'* * * * * * * * * * * * * * *
'HIGHLIGHT NEW CLIENT ACCOUNT CREATIONS
If arrTable(10,i) = "yes" then
highlight = "#FFFFCC"
else
highlight = ""
End if
'* * * * * * * * * * * * * * *
'WRITE LINK FOR NEW CLIENT TAG CREATION (IF TAG EMPTY)
If arrTable(10,i) = "yes" then
If isNull(arrTable(11,i)) OR arrTable(11,i) = "" then
Tagger = "<center><a href=""log.asp?Tagset=" & arrTable(0,i) & "&show=" & Request("show") & "&start=" & Request("start") & """>Create</a></center>"
else
Tagger = arrTable(11,i) & "<a href=""log.asp?Tagset=" & arrTags(2,k) & "&show=" & Request("show") & "&start=" & Request("start") & "&Tagger=" & arrTable(11,i) & """>*</a>"
'RECORD VALUE FOR CLIENT
arrTags(0,count) = arrTable(1,i) 'Client
arrTags(1,count) = arrTable(11,i) 'Tag
arrTags(2,count) = arrTable(0,i) 'ID
count = count + 1
End if
End if
'* * * * * * * * * * * * * * *
'WRITE TAG FOR CLIENT LOGINS
If arrTable(10,i) = "" or IsNULL(arrTable(10,i)) then
for k=0 to ubound(arrTags,1)
If arrTags(0,k) = arrTable(1,i) then
Tagger = arrTags(1,k) & "<a href=""log.asp?Tagset=" & arrTags(2,k) & "&show=" & Request("show") & "&start=" & Request("start") & "&Tagger=" & arrTags(1,k) & """>*</a>"
End if
next
End if
'*****************************
%>

<tr>
<td width="130" height="1" align="left" valign="top" nowrap bgcolor="<%= highlight %>"><%= arrTable(5,i) %></td>
<td width="100" height="1" align="left" valign="top" nowrap bgcolor="<%= highlight %>"><%= arrTable(4,i) %></td>
<td width="200" height="1" align="left" valign="top" nowrap bgcolor="<%= highlight %>"><%= Tagger %></td>
<td width="300" height="1" align="left" valign="top" nowrap bgcolor="<%= highlight %>"><%= arrTable(1,i) %></td>
<td width="100" height="1" align="left" valign="top" nowrap bgcolor="<%= highlight %>"><%= arrTable(3,i) %></td>
<td width="550" height="1" align="left" valign="top" nowrap bgcolor="<%= highlight %>"><%= arrTable(2,i) %></td>
<td width="100" height="1" align="left" valign="top" nowrap bgcolor="<%= highlight %>"><%= arrTable(6,i) %></td>
<td width="300" height="1" align="left" valign="top" nowrap bgcolor="<%= highlight %>"><%= arrTable(7,i) %></td>
</tr>


<%
End Sub
%>



<%
Sub setTag()
%>
<form action="log.asp" name="logger">
<b>Set Tag Value:</b>
<input type="text" name="Tagval" value="<%= Request("Tagger") %>" size="75" style="font-size: 10px; font-family: Verdana; border: 1px solid #000000">
<input type="submit" name="submit" value="save" style="font-size: 10px; font-family: Verdana; border: 1px solid #000000">
<input type="hidden" name="start" value="<%= Request("start") %>">
<input type="hidden" name="show" value="<%= Request("show") %>">
<input type="hidden" name="Tagset" value="<%= Request("Tagset") %>">
</form>
<%
End Sub
%>



<%
Sub saveTag()
%>

<%
Dim adoConB
Dim strSQLB
Dim rsAddData

' ((( ******* BEGIN - ADD DATA TO DB ******** )))


Set adoConB = Server.CreateObject("ADODB.Connection")
adoConB.Open recdb
Set rsAddData = Server.CreateObject("ADODB.Recordset")

strSQLB = "SELECT * FROM log WHERE ID=" & Request("Tagset")

rsAddData.CursorType = 2
rsAddData.LockType = 3

rsAddData.Open strSQLB, adoConB

rsAddData.Fields("tag") = Request("Tagval")

rsAddData.Update
rsAddData.Close
Set adoConB = Nothing
Set strSQLB = Nothing
' ((( *******END - ADD DATA TO DB ******** )))

%>

<%
End Sub
%>

<!--#include file="../inc/interface/html/core.foot.asp"-->

afterburn
11-29-2004, 11:44 AM
Its not a 3 dimension array. its 2d, however your mostlikely its to large and your running out of memory.

AnthonyP
11-29-2004, 07:13 PM
so what do you recommend I do in a situation such as this?
:( ..

afterburn
11-30-2004, 10:47 AM
Originally posted by AnthonyP
so what do you recommend I do in a situation such as this?
:( ..

Instead of creating an array like that let ADO Create it for you with the correct amount of records and fields.

a method of the recordset is GetRows(). That method returns an array of the recordset. It should be what your looking for.