array question (Full Version)

All Forums >> [Web Development] >> ASP, PHP, and Database



Message


bobby -> array question (2/4/2003 16:48:37)

This is my first time really working with an array... and I' m confused about something...

Check out the following from the email list loop I' m trying to make work...

The bolded lines below are supposed to do the following:

1 > reset the variable DUnsub to nothing (added this to try and fix this problem, but it' s not working)

2 > grab a URL (request.form(" unsub" )) and a User ID (myArray(0,i)) and create a URL with a variable attached...

3 > Add that string to the end of the Body...

Heres the problem... in the final email I am getting duplicate strings for the DUnsub variable (the unsubscribe link)...

IOW - at the end of the email is the " unsubscribe" link for the first person on the list, then the closeX HTML code follows... but then there is a duplicate link for each and every subscriber in the list until you get to the one that belongs to that subscriber...

Does that make sense? It' s like the " Next" loop is duplicating the Unsub variable each time it loops and writing the whole thing into the page over and over and over again... but each time with different User ID numbers at the end...

Shouldn' t it " forget" all of those other DUnsub strings as soon as it Loops?

Forgive me while i go mad for a moment...

DMbody=DMbody & " <p>To unsubscribe follow this link:<br>" 
DMbody=DMbody & " (click or copy > paste the URL... )" 

closeX=" </p></td></tr></table></body></html>" 

for i = 0 to uBound(myArray)
DUnsub = " " 
DUnsub = DUnsub & request.form(" unsub" ) & " ?dmkey="  & myArray(0,i)
DMBody=DMBody & DUnsub
DMbody=DMbody & closeX
DMail = myArray(1,i)
set objMail=server.createobject(" CDONTS.newmail" )
objMail.From=" an_email@address" 
objMail.To=DMail
objMail.Subject=" Test" 
objMail.BodyFormat = 0
objMail.MailFormat = 0
objMail.Body=DMBody
objMail.Send
set objMail=nothing
next

 response.redirect (" DMForm.asp?x=3" )
    end if


And here' s what the end of the email looks like (note the multiple unsubscribe links):
quote:

To unsubscribe follow this link:
(click or copy > paste the entire URL below into your browser)

http//www.URLAddress here/page.asp?dmkey=121227

http//www.URLAddress here/page.asp?dmkey=121235

http//www.URLAddress here/page.asp?dmkey=121237


Only the last one is the proper ID # for this subscriber... the others are the first two on the list (in db)!!!




Spooky -> RE: array question (2/4/2003 18:41:09)

Try this?

DMbody=" <p>To unsubscribe follow this link:<br>" 
DMbody=DMbody & " (click or copy > paste the URL... )" 
closeX=" </p></td></tr></table></body></html>" 

for i = 0 to uBound(myArray)
DUnsub = " " 
DUnsub = request.form(" unsub" ) & " ?dmkey="  & myArray(0,i)

set objMail=server.createobject(" CDONTS.newmail" )
objMail.From=" an_email@address" 
objMail.To=myArray(1,i)
objMail.Subject=" Test" 
objMail.BodyFormat = 0
objMail.MailFormat = 0
objMail.Body=DMBody& DUnsub& closeX
objMail.Send
set objMail=nothing

next

 response.redirect (" DMForm.asp?x=3" )
    end if





SerenityNet -> RE: array question (2/4/2003 20:41:28)

This is just a question from the slow section...
but why are you using a multi-dimensional array. Wouldn' t myarray(i) work?




bobby -> RE: array question (2/5/2003 0:46:02)

Spooky you' re a godsend.

Why the difference? Is there some fundamental syntax heirarchy that I' m missing? Or is that just another way of doing it that happens to work?

quote:

why are you using a multi-dimensional array. Wouldn' t myarray(i) work?

Couldn' t tell you... I' ve only been working with arrays for about a week [&:]
Already starting to like them... for some things. [;)]

What' s the difference between (i) and (0,i) - besides the 0 and 1 telling the server which record to grab from the row..?

Multi-dimensional array... ...sounds cool.

Can I get an OF T-Shirt that says:
" I use multi-dimensional array' s because it sounds cool." [:D]




Spooky -> RE: array question (2/5/2003 1:15:32)

This is where you tripped and couldnt get up.
DMBody=DMBody & DUnsub 

DMBody wasnt reset, so I did it without concatenating the string each time.

Andrew, the array comes from a database using getrows so it becomes multidifuntionmental [:D]




rdouglass -> RE: array question (2/5/2003 9:11:18)

quote:

multidifuntionmental


LOL!!!![:D] (Sorry..couldn' t resist!!)




bobby -> RE: array question (2/5/2003 10:40:54)

Egad! So simple! And yet so immensely complex that I sweated over it for a million billion years... okay, it was a matter of a couple days... but still... [8|]

Thanks again!




SerenityNet -> RE: array question (2/5/2003 12:12:10)

Bobby, if I' ve said it once then I' ve said it a quad-zillion times, " Don' t exaggerate!"

But anyway, I guess I' m a visual person. I looked at the WROX samples (where I got the multi-dimensional array phrase - wish I had thought it up) and it is all still out of focus. Spooky, Bobby, any chance you could clarify this for me. I wouldn' t mind giving these things a glance.




bobby -> RE: array question (2/5/2003 12:50:13)

I have another question guys...

Why is it that .getrows above is only grabbing the first 3 records in the DB?

I removed the Where clause from the Select statement, still only grabs the first three...

I added:
myArray=" " 
myArray=rsMail.getrows

to try and " clear" it out each time, but it still only grabs the first three records...

I also rewrote the page to use a Do While... Loop and it grabs all of the records!!!

Why is getrows not working the way I think it should?

_________

Andrew,

The array above is calling for specific records within each row of the recordset... (0,i) would be the first column (0) of the current row (i) - where (1,i) is grabbing the second column (1) from the current row (i)

Since this stuff is zero based you have to start with 0 instead of 1...

That help?

:edit:

Oops, forgot that the recordset code wasn' t included above... here it is:
dim rsMail,DMtxt,myArray

set rsMail=server.createobject(" ADODB.recordset" )
DMtxt=" Select * From tblMail" 
rsMail.open DMtxt, oConn, 3,3,1

  if rsMail.EOF then
   rsMail.close
    set rsMail=nothing
     oConn.close
      set oConn=nothing
       response.write " <p>Error at rsMail.DMProcess</p>" 
  else
   myArray=" " 
    myArray=rsMail.getrows
     rsMail.close
      set rsMail=nothing
   
        oConn.close
         set oConn=nothing
  
   end if

for i = 0 to uBound(myArray)
DUnsub = " " 
DUnsub = request.form(" unsub" ) & " ?dmkey="  & myArray(0,i)
DUnsub = " <a href=' "  & DUnsub & " ' >"  & DUnsub & " </a>" 
DMail = myArray(1,i)
set objMail=server.createobject(" CDONTS.newmail" )
objMail.From=" codeslinger@bdwebservices.com" 
objMail.To=DMail
objMail.Subject=" Test From DragonMail" 
objMail.BodyFormat = 0
objMail.MailFormat = 0
objMail.Body=DMBody & DUnsub & closeX
' objMail.Send
response.write DMail & " <br>" 
set objMail=nothing
next




rdouglass -> RE: array question (2/5/2003 13:09:46)

quote:

for i = 0 to uBound(myArray)


You' re only getting 3 records ' cause you' re only grabbing 3 fields and you' re defaulting to the column numbers. So when you use uBound(myArray), you' re actually saying uBound(myArray,1). Try using:

for i = 0 to uBound(myArray,2)

As Spooky said, getrows is already mlti-di so we need to specify that we want to use the rownumber.

Hope it helps...




erinatkins -> RE: array question (2/5/2003 13:19:57)

Bobby,

Seems like a complicated project to me. Please keep posting - I am learning quite a bit from this.[:D]

Rd & Spooky thanks for explaining some basics to us ASP challenged people. I am really trying to understand ASP/DB more.

Erin




bobby -> RE: array question (2/5/2003 13:46:58)

RD, I owe you a beer next time you' re in Seattle... [:D][:D][:D]

Thank you! Thank you! Thank you! Thank you! Thank you!

That did it!

When you get a minute, could you give me a little more expanation on that? Or a link to some info...

I get that ...uBound(myArray) is the same as (myArray,1) - default, right?

But what is that ,1 - or more to the point, what does changing it to ,2 do?

What would happen if I changed to ,3 or ,5 ?

(not going to right now because I think that was the last major glitch in my code... [:D][:D][:D][:D][:D][:D])

Again, this forum is well worth the fee that I send to Spooky each month! [:p]




SerenityNet -> RE: array question (2/5/2003 14:23:51)

Roger, I' m also curious to know about the ,2). My ASP book is at home and I' m (supposed to be) working. I' m not sure I can survive the suspense of waiting until I get home.

Erin, ditto from me. I' ve learned a tremendous amount from this post. (Enough to suggest a solution to a gripe I have with our corporate web designers. Enough even to justify following this post while at work!




rdouglass -> RE: array question (2/5/2003 14:52:52)

quote:

for i = 0 to uBound(myArray,2)


The two is the dimension #' of the array. By default dimension # 1 is ' column #' , dimension #2 is ' row #' . Those are the only two I use, but I have read about 3 & 4 dimension arrays - they get VERY complicated IMO. However, 2D arrays you can treat like a spredsheet and address individual ' cells' . For instance:

(* remember arrays are 0-based so the first item is 0 and not 1)
myArray(1,1) represents myArray(column2,row2)
myArray(3,7) represents myArray(column4,row8)

Does that make sense?

Now to further follow this, when I call ' uBound' on an array, we are supposed to specify which item we want to ' uBound' . VBScript assumes we' re looking at the first dimension (columns) unless we specify otherwise. So to count the number of rows in a 2D array, we need to tell uBound to use the second dimension. Hence:

uBound(myArray,2)

I learned lots of stuff about arrays at http://www.learnasp.com/learn/index.asp

Does that help?

EDIT: Cant spell!!![:o]




bobby -> RE: array question (2/5/2003 15:44:41)

Aha!

So, (myArray) is the same as (myArray,1) and that tells the array to grab columns as the uBound limit..?

(Since my table only had 3 columns, maybe this is why it only grabbed the first three records?)

Whereas (myArray,2) tells the array to grab the rows..? (or all available records)

That almost makes sense... sort of... [:p]

Thanks for the explanation. I' m off to see what more I can find. [;)]




SerenityNet -> RE: array question (2/5/2003 16:15:34)

I think I have a slippery grasp on the array. Thank you.

But Bobby, let me ask you a beginner question about your connection string. Will you translate for me the line rsMail.open DMtxt, oConn, 3,3,1 ? What are the 3,3,1 representing?



PS. I saw in my WROX book last night that you could have up to 60 dimensions. That would make an interesting thread.




rdouglass -> RE: array question (2/5/2003 16:43:53)

quote:

PS. I saw in my WROX book last night that you could have up to 60 dimensions. That would make an interesting thread.


Yuck!!! How would you manage the loops - an array of loops?....[:o][:' (] I have a hard enough time trying to think of 3D.....[:p]




bobby -> RE: array question (2/5/2003 16:51:13)

quote:

What are the 3,3,1 representing?


Cursor type in the recordset. I use 3,3,1 any time I' m using Count, or where I may have to bounce back and forth between records... usually in development like where I am now.

With the default cursor you can' t move backward, or start looping again to count records, etc.

I forget exactly what they stand for... I' m pretty sure there' s an " adlock" in there and an " optimistic" too, but I don' t remember what the specific names are...

:edit:

Heres a link that Doug G posted many moons ago...
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/mdmthrstopen.asp




SerenityNet -> RE: array question (2/5/2003 18:29:19)

Thanks all. [:D] This has been the most educational thread that I' ve encounted in a while. I appreciate you taking the time to answer my questions.


Chaos, panic, & disorder - my work here is done.




bobby -> RE: array question (2/6/2003 10:11:29)

quote:

This has been the most educational thread that I' ve encounted in a while


You' re telling me... I haven' t had an " Aha!" moment like this in a while...

SPOON!

[:p]




rdouglass -> RE: array question (2/7/2003 8:36:28)

quote:

Cursor type in the recordset. I use 3,3,1 any time I' m using Count, or where I may have to bounce back and forth between records... usually in development like where I am now.


That' s one of the reasons I like to use arrays - you don' t have to keep the DB conn open. Just dump ' em in the array and close the DB...[:)]

</$.02>




SerenityNet -> RE: array question (2/7/2003 9:12:18)

Since I' m being hosted on a shared server, isn' t there a point that I' d affect server &/or page performance (I' m assuming the stored array stays server side.)




rdouglass -> RE: array question (2/7/2003 9:24:05)

quote:

(I' m assuming the stored array stays server side.)


Actually, the array is not ' stored' at all rather ' used' only during the time it takes the page to process (unless you store it in a session or something and that would probably be a bad idea).

So in terms of performance, you' ll generally see better results by reducing the DB connection overhead. At least in my experience, that is....[:)]




Spooky -> RE: array question (2/7/2003 14:49:11)

I think its explained fairly well here too :
http://www.learnasp.com/learn/whygetrows.asp [:D]




SerenityNet -> RE: array question (2/7/2003 18:25:42)

I thought I was doing okay with my database connections. They worked! [&:] Now I' m beginning to think that I know next to nothing! [:(] Is there a better way to write <br> of which I' m not aware?




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.1408691