473,769 Members | 6,831 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

arrays and recordsets

Hi there,

I am trying to populate the array "yourImages " in the following code,
http://www.javascriptkit.com/script/...adimage2.shtml
except i am trying to fill it with the values from an access database.
I already publish info from the database to an asp page, but i would like to
preload the images.

I open the database successfully like this
---------------
<%
If IsObject(Sessio n("Fragrance_co nn")) Then
Set conn = Session("Fragra nce_conn")
Else
Set conn = Server.CreateOb ject("ADODB.Con nection")
conn.open "Fragrance","", ""
Set Session("Fragra nce_conn") = conn
End If
%>
<%
If IsObject(Sessio n("retail_rs" )) Then
Set rs = Session("retail _rs")
Else
sql = "SELECT * FROM [retail]"
Set rs = Server.CreateOb ject("ADODB.Rec ordset")
rs.Open sql, conn, 3, 3
If rs.eof Then
rs.AddNew
End If
Set Session("retail _rs") = rs
End If"
---------------------
The record i want to use is
rs.Fields("Imag es").Value

Could anyone please help me out?

Thanks

Jul 20 '05 #1
4 1812
Stuart,

It's considered bad practise to store connection or recordset objects
objects in session variables (search relevant FAQ's for the reason).
It's much better to create connections as needed and to store data in
arrays rather than a rs.

Anyway, once you have your recordset then just loop through it and add
the items:

strImgBase = "http://www.mysite.com/images/"
strArr = ""

if not rs.eof then
do while not rs.eof

strArray = strArray & """" & _
strImgBase & rs("Images").va lue & ""","

rs.movenext
loop
end if

strArray=left(s trArray,len(str Array)-1)
//then in the js preload script
var yourImages = new Array(<%=strArr ay%>) // Fill this array with the
images you wish to preload

stuff strArray in a session (or application variable) to cache it for
the next use.
Tim.
"Stuart" <st****@nexusne t.co.nz> wrote in message
news:bt******** **@lust.ihug.co .nz...
Hi there,

I am trying to populate the array "yourImages " in the following code, http://www.javascriptkit.com/script/...adimage2.shtml
except i am trying to fill it with the values from an access database. I already publish info from the database to an asp page, but i would like to preload the images.

I open the database successfully like this
---------------
<%
If IsObject(Sessio n("Fragrance_co nn")) Then
Set conn = Session("Fragra nce_conn")
Else
Set conn = Server.CreateOb ject("ADODB.Con nection")
conn.open "Fragrance","", ""
Set Session("Fragra nce_conn") = conn
End If
%>
<%
If IsObject(Sessio n("retail_rs" )) Then
Set rs = Session("retail _rs")
Else
sql = "SELECT * FROM [retail]"
Set rs = Server.CreateOb ject("ADODB.Rec ordset")
rs.Open sql, conn, 3, 3
If rs.eof Then
rs.AddNew
End If
Set Session("retail _rs") = rs
End If"
---------------------
The record i want to use is
rs.Fields("Imag es").Value

Could anyone please help me out?

Thanks

Jul 20 '05 #2
I agree ... check out my DBConn.asp script at the following ...

http://www.coolpier.com/cp/cp_scripts/index.asp

this gets you in and out of your database incredibly fast using the
getrows method ... much faster than looping through a recordset at
all. This way you wil build the string after your recordset and
database connection is closed.
GetRows will give you a 2-dimensional array of your recordset ...
first dimension columns, second dimension rows. Yours just being 1
column will be like the below loop. I would be sure to put Select
Images From [retail]; instead of * ... if you don't need the other
info.

I recommend putting your connection string in an application variable
via the global.asa ... or just set it on the page like so ...

I like the way Tim got rid of last comma .. good idea Tim ... versus
if .. then in the loop

<!-- #include file="/coolpier_script s/_database_tools/DBConn.asp" -->

<%
Dim yourSqlStatemen t, rsArray, strArray: strArray=""
yourSqlStatemen t = "SELECT Images FROM [retail];"

cp_TheConnectio nString = "yourConnection String"
cp_DBConn(("ope n")
rsArray = cp_SqlArray(you rSqlStatement)
cp_DBConn("clos e")

strImgBase = "http://www.mysite.com/images/"
For n = 0 to ubound(rsArray, 2)
strArray = strArray & """" & strImgBase & rsArray(0,n) & ""","
Next
strArray=left(s trArray,len(str Array)-1) '//to get rid of last comma
%>


On Thu, 08 Jan 2004 05:35:58 GMT, "Tim Williams"
<sa************ @THISpacbell.ne t> wrote:
Stuart,

It's considered bad practise to store connection or recordset objects
objects in session variables (search relevant FAQ's for the reason).
It's much better to create connections as needed and to store data in
arrays rather than a rs.

Anyway, once you have your recordset then just loop through it and add
the items:

strImgBase = "http://www.mysite.com/images/"
strArr = ""

if not rs.eof then
do while not rs.eof

strArray = strArray & """" & _
strImgBase & rs("Images").va lue & ""","

rs.movenext
loop
end if

strArray=left( strArray,len(st rArray)-1)
//then in the js preload script
var yourImages = new Array(<%=strArr ay%>) // Fill this array with the
images you wish to preload

stuff strArray in a session (or application variable) to cache it for
the next use.
Tim.
"Stuart" <st****@nexusne t.co.nz> wrote in message
news:bt******* ***@lust.ihug.c o.nz...
Hi there,

I am trying to populate the array "yourImages " in the following

code,
http://www.javascriptkit.com/script/...adimage2.shtml
except i am trying to fill it with the values from an access

database.
I already publish info from the database to an asp page, but i would

like to
preload the images.

I open the database successfully like this
---------------
<%
If IsObject(Sessio n("Fragrance_co nn")) Then
Set conn = Session("Fragra nce_conn")
Else
Set conn = Server.CreateOb ject("ADODB.Con nection")
conn.open "Fragrance","", ""
Set Session("Fragra nce_conn") = conn
End If
%>
<%
If IsObject(Sessio n("retail_rs" )) Then
Set rs = Session("retail _rs")
Else
sql = "SELECT * FROM [retail]"
Set rs = Server.CreateOb ject("ADODB.Rec ordset")
rs.Open sql, conn, 3, 3
If rs.eof Then
rs.AddNew
End If
Set Session("retail _rs") = rs
End If"
---------------------
The record i want to use is
rs.Fields("Imag es").Value

Could anyone please help me out?

Thanks



Jul 20 '05 #3
I was playing woith someone elses script and i kind of got it working to an
extent. The reason i am trying to preload *some* images is that there are
4000 plus records that i will be displaying in a table, which includes a
picture of each item. I would like to split it into pages displaying maybe
50 items max, but i don't know how to do that yet. Here is the kind of
working script i am playing with

<html>
<%
If IsObject(Sessio n("Fragrance_co nn")) Then
Set conn = Session("Fragra nce_conn")
Else
Set conn = Server.CreateOb ject("ADODB.Con nection")
conn.open "Fragrance","", ""
Set Session("Fragra nce_conn") = conn
End If
%>
<%
If IsObject(Sessio n("retailU_rs") ) Then
Set rs = Session("retail U_rs")
Else
sql = "SELECT * FROM [retailU]"
Set rs = Server.CreateOb ject("ADODB.Rec ordset")
rs.Open sql, conn, 3, 3
If rs.eof Then
rs.AddNew
End If
Set Session("retail U_rs") = rs
End If
%>
<head>
<script language="JavaS cript1.2">
<!-- begin hiding
// (C) 2000 Marcin P Wojtowicz [on*******@hotma il.com]. All rights reserved.
// Obtain permission before selling/redistributing in any medium.

startingColor = new Array() // <-- Do not modify!
endingColor = new Array() // <-- Do not modify!

// YOU MAY MODIFY THE FOLLOWING:
var yourImages = new Array() // Fill this array with the images you wish to
preload

<%
x = 0
On Error Resume Next
rs.MoveFirst
do while Not rs.eof //x <= 151

x = x + 1

response.write( "yourImages[" & x & "]=" & "'" & rs("Images") & "';")

rs.MoveNext
loop
%>
document.write( yourImages.leng th);

var locationAfterPr eload = "http://192.168.1.3/retail.asp" // The script
will redirect here when the preloading finishes *successfully*
var preloadbarWidth = 4000 // 151 The length of the preload bar. Should be
greater than total amount of images you want to preload!
var preloadbarHeigh t = 15 // The height of the gradient/preload bar
var backgroundOfGra dient = "#000000" // Default color while the preload bar
is "filling up"

// Color the preloadbar is starting with - enter 1st, 3rd and 5th
numbers/letters of color code
startingColor[0] = "c"
startingColor[1] = "f"
startingColor[2] = "f"

// Color the preloadbar is going to end up with - enter the 1st, 3rd and 5th
numbers/letters of color code
endingColor[0] = "c"
endingColor[1] = "0"
endingColor[2] = "0"

// FOR TROUBLESHOOTING :
var gap = 2 // PLAY AROUND WITH THIS SETTING IF YOU GET A JAVASCRIPT
ERROR!!! 2 is the minumum value!!!
// DO NOT MODIFY ANYTHING BEYOND THIS POINT!!!

if (!document.all) location.replac e(locationAfter Preload)
var a = 10, b = 11, c = 12, d = 13, e = 14, f=15, i, j, ones = new Array(),
sixteens = new Array(), diff = new Array();
var convert = new
Array("0","1"," 2","3","4","5", "6","7","8","9" ,"a","b","c","d ","e","f"),
imgLen = yourImages.leng th;
var loaded = new Array(), preImages = new Array(), currCount = 0, pending =
0, h = 0, hilite = new Array(), cover = new Array();

var num = Math.floor(prel oadbarWidth/gap);
for (i = 0; i < 3; i++) {
startingColor[i] = startingColor[i].toLowerCase();
endingColor[i] = endingColor[i].toLowerCase();
startingColor[i] = eval(startingCo lor[i]);
endingColor[i] = eval(endingColo r[i]);
diff[i] = (endingColor[i]-startingColor[i])/num;
ones[i] = Math.floor(diff[i]);
sixteens[i] = Math.round((dif f[i] - ones[i])*15);
}
endingColor[0] = 0;
endingColor[1] = 0;
endingColor[2] = 0;
i = 0, j = 0;
while (i <= num) {
hilite[i] = "#";
while (j < 3) {
hilite[i] += convert[startingColor[j]];
hilite[i] += convert[endingColor[j]];
startingColor[j] += ones[j];
endingColor[j] += sixteens[j];
if (endingColor[j] > 15) {
endingColor[j] -= 15;
startingColor[j]++;
}
j++;
}
j = 0;
i++;
}
function loadImages() {
for (i = 0; i < imgLen; i++) {
preImages[i] = new Image();
preImages[i].src = yourImages[i];
loaded[i] = 0;
cover[i] = Math.floor(num/imgLen)*(i+1)
}
cover[cover.length-1] += num%imgLen
checkLoad();
}
function checkLoad() {
if (pending) { changeto(); return }
if (currCount == imgLen-1) { location.replac e(locationAfter Preload);
return }
for (i = 0; i < imgLen; i++) {
if (!loaded[i] && preImages[i].complete) {
loaded[i] = 1; pending++; currCount++;
checkLoad();
return;
}
}
setTimeout("che ckLoad()",10);
}
function changeto() {
if (h+1 > cover[currCount-1]) {
var percent = Math.round(100/imgLen)*currCou nt;
if (percent > 100) while (percent != 100) percent--;
if (currCount == imgLen && percent < 100) percent = 100;
defaultStatus = "Loaded " + currCount + " out of " + imgLen + " images ["
+ percent + "%].";
pending--;
checkLoad();
return;
}
eval("document. all.cell" + (h+1) + ".style.backgro undColor = hilite[h]");;
h++;
setTimeout("cha ngeto()",1);
}
defaultStatus = "Loaded 0 out of " + imgLen + " images [0%]."
// end hiding -->
</script>
</head>
<body>
<center>
<font face="Verdana, Arial, Helvetica" size="2"><cente r>Preloading Images...
Please Wait..</center>
<script language="JavaS cript1.2">
<!-- beging hiding
document.write( '<table border="0" cellpadding="0" cellspacing="0" width="' +
preloadbarWidth + '"><tr height="' + preloadbarHeigh t + '" bgcolor="' +
backgroundOfGra dient + '">');
for (i = 0; i < num; i++) {
document.write( '<td width="' + gap + '" id="cell' + (i+1) + '"></td>');
}
document.write( '</tr></table>');
document.write( '<p><small><a
href="javascrip t:location.repl ace(locationAft erPreload)">Ski p Preloading</a>
&nbsp;| &nbsp;<a
href="http://javascriptkit.c om/script/script2/preloadimage2.s html">Script
Credits</a></small></p></font>')
loadImages();
// end hiding -->
</script>
</center>
</body>
</html>


"Brynn" <z@z.com> wrote in message
news:3f******** *******@news.co mcast.giganews. com...
I agree ... check out my DBConn.asp script at the following ...

http://www.coolpier.com/cp/cp_scripts/index.asp

this gets you in and out of your database incredibly fast using the
getrows method ... much faster than looping through a recordset at
all. This way you wil build the string after your recordset and
database connection is closed.
GetRows will give you a 2-dimensional array of your recordset ...
first dimension columns, second dimension rows. Yours just being 1
column will be like the below loop. I would be sure to put Select
Images From [retail]; instead of * ... if you don't need the other
info.

I recommend putting your connection string in an application variable
via the global.asa ... or just set it on the page like so ...

I like the way Tim got rid of last comma .. good idea Tim ... versus
if .. then in the loop

<!-- #include file="/coolpier_script s/_database_tools/DBConn.asp" -->

<%
Dim yourSqlStatemen t, rsArray, strArray: strArray=""
yourSqlStatemen t = "SELECT Images FROM [retail];"

cp_TheConnectio nString = "yourConnection String"
cp_DBConn(("ope n")
rsArray = cp_SqlArray(you rSqlStatement)
cp_DBConn("clos e")

strImgBase = "http://www.mysite.com/images/"
For n = 0 to ubound(rsArray, 2)
strArray = strArray & """" & strImgBase & rsArray(0,n) & ""","
Next
strArray=left(s trArray,len(str Array)-1) '//to get rid of last comma
%>


On Thu, 08 Jan 2004 05:35:58 GMT, "Tim Williams"
<sa************ @THISpacbell.ne t> wrote:
Stuart,

It's considered bad practise to store connection or recordset objects
objects in session variables (search relevant FAQ's for the reason).
It's much better to create connections as needed and to store data in
arrays rather than a rs.

Anyway, once you have your recordset then just loop through it and add
the items:

strImgBase = "http://www.mysite.com/images/"
strArr = ""

if not rs.eof then
do while not rs.eof

strArray = strArray & """" & _
strImgBase & rs("Images").va lue & ""","

rs.movenext
loop
end if

strArray=left( strArray,len(st rArray)-1)
//then in the js preload script
var yourImages = new Array(<%=strArr ay%>) // Fill this array with the
images you wish to preload

stuff strArray in a session (or application variable) to cache it for
the next use.
Tim.
"Stuart" <st****@nexusne t.co.nz> wrote in message
news:bt******* ***@lust.ihug.c o.nz...
Hi there,

I am trying to populate the array "yourImages " in the following

code,
http://www.javascriptkit.com/script/...adimage2.shtml
except i am trying to fill it with the values from an access

database.
I already publish info from the database to an asp page, but i would

like to
preload the images.

I open the database successfully like this
---------------
<%
If IsObject(Sessio n("Fragrance_co nn")) Then
Set conn = Session("Fragra nce_conn")
Else
Set conn = Server.CreateOb ject("ADODB.Con nection")
conn.open "Fragrance","", ""
Set Session("Fragra nce_conn") = conn
End If
%>
<%
If IsObject(Sessio n("retail_rs" )) Then
Set rs = Session("retail _rs")
Else
sql = "SELECT * FROM [retail]"
Set rs = Server.CreateOb ject("ADODB.Rec ordset")
rs.Open sql, conn, 3, 3
If rs.eof Then
rs.AddNew
End If
Set Session("retail _rs") = rs
End If"
---------------------
The record i want to use is
rs.Fields("Imag es").Value

Could anyone please help me out?

Thanks


Jul 20 '05 #4
Stuart wrote:
I open the database successfully like this
---------------
<%
If IsObject(Sessio n("Fragrance_co nn")) Then
Set conn = Session("Fragra nce_conn")
Else
Set conn = Server.CreateOb ject("ADODB.Con nection")
conn.open "Fragrance","", ""
Set Session("Fragra nce_conn") = conn
End If
%>


What the heck has this to do with JavaScript?
Go away, to a <jehova>VBScrip t</jehova> NG, please.
PointedEars
Jul 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
2718
by: middletree | last post by:
OK, you pros out there are rolling your eyes at the subject line, but I have never had to use arrays before. The scenario: ASP Intranet app keeps track of trouble tickets for a tech support group. Table called Ticket has one row per ticket. Table named History has 0, 1, or many rows per ticket. As the tech support person makes notes to update the ticket, it adds a new row per entry into History table. One of the things storeed in this...
0
1282
by: Lee Holsenbeck | last post by:
hi, i'm reading recordsets into arrays and need to read them from other procedures and resize them based on the record size, but cannot do both of those without an error. anyone know how to make a multi-dimensional array that you resize available to other procedures w/in a module/class ? thanks, Lee
50
11642
by: SABmore | last post by:
Is there a performance advantage to parsing thru a recordset verus using an array? I'm currently trying to populate a listbox by returning data from my database, then either parsing thru the recordset until I reach the EOF, or putting the data into an array. Thanks for your assistance.
6
2948
by: Steve Jorgensen | last post by:
I keep having problems in which ADO disconnected recordset work under some circumstances, but lose all their data at other times, having no rows or fields, though the recordset object still exists. One case where this happened to me today was in trying to store disconnected recordsets in a cache collection in case they are needed again later in the same session. When I retrieve the recordset from the collection, it's empty. On the other...
3
1967
by: madsen | last post by:
Hi, I am a developper who needs to return a collection of different datatypes. Have considered using an array containing arraylists. Is it posible? or is there a better way? Would like to use some kind of 2 dim arraylist, like Vectors in JAVA... Carsten
7
1610
by: Matt | last post by:
Is there a way to put my class vals to arrays ! RecordSet Track1 = new RecordSet("It aint fear",1); RecordSet Track2 = new RecordSet("Gotta go",2); RecordSet Track3 = new RecordSet("My life",3); RecordSet Track4 = new RecordSet("Amazing",4); Data d = new Data(); d.RecordAdd(Track1);
16
5726
by: Randy Harris | last post by:
I was inspired by the recent discussion of returning multiple recordsets to ADO from a stored procedure. (Amazed is probably more accurate). I asked about how to accomplish same with Oracle and got a nudge in the right direction from Mr. Kreft. I promised to provide details once working, so here it is. The code is shown below. My next step is to build this technique into my application. I'm hoping for substantial performance gain. ...
4
1514
by: mrmagoo | last post by:
I'm building a vb.net Forms project that is getting data from a SQL Server database. One of the main goals of the project is to be really responsive to events, such as textbox change events. I have a textbox for searching, a listbox to display the searched results, and a big textbox (memo) to display the clicked-results of the listbox item. My question is: should I load the controls with objects, and therefore store everything in...
4
2438
by: rdemyan via AccessMonster.com | last post by:
Can someone help me with creating code that will look for DAO recordsets in modules and then check to see if the recordset is also closed in the module. All of my recordsets are of the form rs* where * is a wildcard for letters after rs. Thanks. -- Message posted via AccessMonster.com
0
9590
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10223
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10000
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8879
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7413
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3968
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3571
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.