Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help printing results from a table on asp page

Status
Not open for further replies.

karren

Programmer
Feb 26, 2002
42
CA
Hi everyone,

I am working with a couple of tables and am having trouble printing out the right results on my asp page.

This is what i'm trying to do:

I am working on a newsletter app. and have a form with muliple select checkboxes for the user to subscribe to a list. This checkbox form is populated from a database, where the input name and value is "newsletterID", which is coming from a table with an "newsletterID" column as well as an "newslettername" column.

when this form information is passed to the processing page, I want to print out the "newslettername" of the newsletters that the person has subscribed to, rather than the "newsletterID" that is the value in the checkboxes.

i have split the checkbox string into an array then put an SQL statement in a "for each loop", in the following way:

Dim objRS5, strSQL5, icount2

set objRS5 = server.CreateObject("ADODB.Recordset")

for each icount2 in split_news 'split_news is the array of newsletterID that the user has subscribed to

strSQL5 = "SELECT * FROM artistnames WHERE artistnameID = " & icount2 & ";"
next
objRS5.open strSQL5, objConn
for each icount2 in split_news
do while not objRS5.EOF
response.write objRS5("artistname")
objRS5.MoveNext
loop
next

when i do this, i am only getting the last "newslettername" rather than all of them. does anyone know how i can fix this? what am i doing wrong here?

thanks all, i really appreciate it!! :)

karren
 
sorry, the "artistnameID" and "artistname" in my previous posts should be "newsletterID" and "newslettername"!
 
if split_news is an array, you should be iterating it like such:

for x = 0 to ubound(split_news)
strSQL5 = "SELECT * FROM artistnames WHERE artistnameID = " & split_news(x) & ";"
next =========================================================
if (!succeed) try();
-jeff
 
hi Jeff,
thanks so much for responding :) i tried the code that you wrote, but i'm still getting the same results...i tried some thing else though and it worked!

this is the code i used:
Dim objRS5, strSQL5, icount2

for icount2=0 to ubound(split_news) 'split_news is the array variable which contains all the newsletterIDs
set objRS5 = server.CreateObject("ADODB.Recordset")
strSQL5 = "SELECT * FROM newsletters WHERE newsletterID = " & split_news(icount2) & ";"
objRS5.open strSQL5, objConn
do while not objRS5.EOF
response.write &quot;<li>&quot; & objRS5(&quot;newslettername&quot;) & &quot;</li>&quot;
objRS5.MoveNext
loop
next

thanks for your tips!

karren
 
ur erros is this: (IN CAPS)
for each icount2 in split_news 'split_news is the array of newsletterID that the user has subscribed to

strSQL5 = &quot;SELECT * FROM artistnames WHERE artistnameID = &quot; & icount2 & &quot;;&quot;
'COMMENT THIS next
objRS5.open strSQL5, objConn
for each icount2 in split_news
do while not objRS5.EOF
response.write objRS5(&quot;artistname&quot;)
objRS5.MoveNext
loop
next
next 'THIS IS ERROR PUT THE NEXT IN THE END
 
hi karren,

yes - you figured it out: in your original code, your for-next loop that set strSQL5 was completing before you opened the recordset, so you were always just getting the results of the last loop.

=========================================================
if (!succeed) try();
-jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top