Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 Same Record Displayed Multiple Times
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

Suamere
Starting Member

27 Posts

Posted - 10 February 2005 :  13:55:23  Show Profile  Visit Suamere's Homepage  Send Suamere an AOL message  Send Suamere a Yahoo! Message
I don't know why I can't figure it out... But here is the outcome, and then the code:
Outcome:
You gave Suamere 10 Rupees on 2/9/05.
You gave Suamere 10 Rupees on 2/9/05.
You gave Suamere 10 Rupees on 2/9/05.
You gave Suamere 10 Rupees on 2/9/05.
You gave Suamere 10 Rupees on 2/9/05.
You gave Suamere 10 Rupees on 2/9/05.
You gave Suamere 10 Rupees on 2/9/05.


<%
rs.Open "Select * from Transactions WHERE ComingFrom = '" & strUserName & "' and IsNull(IfItemID)=True", conn
Dim IfAmount
Dim GivenTo
Dim DateGiven
%>
<%do until rs.EOF%>
<%for each x in rs.Fields%>
<%
IfAmount = rs("IfAmount")
GivenTo = rs("GivenTo")
DateGiven = rs("Date")

Response.Write("You gave " & IfAmount & " Rupees to " & GivenTo & " on " & DateGiven & ".<br>")

%>
<%next
rs.MoveNext%>
<%loop
rs.close
%>


I also know that the record is repeated the same number of times as there are columns in that table... It's probably something simple, I know.

If something goes wrong, find the source of the problem and break it's legs.

Da_Stimulator
DEV Team Forum Moderator

USA
3373 Posts

Posted - 10 February 2005 :  15:49:37  Show Profile  Send Da_Stimulator an AOL message  Send Da_Stimulator a Yahoo! Message
Consolidate this:


%>
<%do until rs.EOF%>
<%for each x in rs.Fields%>
<%
IfAmount = rs("IfAmount")
GivenTo = rs("GivenTo")
DateGiven = rs("Date")

Response.Write("You gave " & IfAmount & " Rupees to " & GivenTo & " on " & DateGiven & ".<br>")

%>
<%next
rs.MoveNext%>


into this:


<%
rsData = rs.GetRows

For i = 0 to Ubound(rsData, 2)
  IfAmount = rsData(0, i)
  GivenTo  = rsData(1, i)
  DateGiven= rsData(2, i)

  Response.Write("You gave " & IfAmount & " Rupees to " & GivenTo & " on " & DateGiven & ".<br>")

Next
%>


In order for that to work correctly, the SQL statement must call those fields in that exact order, Ie: SELECT IfAmount, GivenTo, Date FROM blah blah where blah blah

Edit: The reason you're getting multiple occurances of the same record is because your looping a for with the recordset, while doing a loop (do until rs.eof) and (for each x in rs.fields) where you should either be using one or the other, not both. Getrows is much quicker though when displaying alot of data.

-Stim

Edited by - Da_Stimulator on 10 February 2005 15:53:18
Go to Top of Page

Suamere
Starting Member

27 Posts

Posted - 10 February 2005 :  16:41:17  Show Profile  Visit Suamere's Homepage  Send Suamere an AOL message  Send Suamere a Yahoo! Message
How do I modify that? I don't know what the unbound thing is, I haven't seen that in For statements before (Noob enough?) But I would like to do an i = 0 to 10. Or something like that. I just want to show the last 10 records. Can that same code have that added? I tried these two:

For i = 0 to 10
And
For i = 0 to 10 Ubound(rsData, 2)

The first one worked, but it said
Subscript out of range: 'i'
And nothing else worked in my code after that point.

If something goes wrong, find the source of the problem and break it's legs.
Go to Top of Page

Da_Stimulator
DEV Team Forum Moderator

USA
3373 Posts

Posted - 10 February 2005 :  19:16:11  Show Profile  Send Da_Stimulator an AOL message  Send Da_Stimulator a Yahoo! Message
in your select code, use "SELECT TOP 10 field1, field2, etc..."

Then use the code I showed you above to show it.

Ubound(rsData, 2) grabs the "upper" bound record in the array, in the row form (its a 2 dimensional array... search around on some asp resource sites to learn more about arrays)

For i=0 to Ubound(rsData, 2)

That line is essentially telling the server "From the beginning of the array to the end of the array, display this data", "this" being the row in question (i).

If you have IfAmount, GivenTo, and DateGiven being called from the recordset, in that order, rs.Getrows will return an array shaped like so:


   0(IfAmount)  |   1(GivenTo)   |   2(DateGiven)
Row1  Value     |     Value      |     Value
Row2  Value     |     Value      |     Value
Etc...


rsData(0, 0) = Value of IfAmount in the first row
rsData(0, 1) = Value of IfAmount in the second row

rsData(1, 0) = value of GivenTo in the first row
rsData(1, 1) = Value of GivenTo in the second row

rsData(2, 0) = Value of DateGiven in the first row
rsData(2, 1) = Value of DateGiven in the second row

and so on. It will essentially build an array table mimicing the Table your calling in the recordset.

Hope this explanation helped

-Stim

Edited by - Da_Stimulator on 10 February 2005 19:16:52
Go to Top of Page

Suamere
Starting Member

27 Posts

Posted - 10 February 2005 :  21:02:24  Show Profile  Visit Suamere's Homepage  Send Suamere an AOL message  Send Suamere a Yahoo! Message
Awesome once again. I had to do some additional tweaking myself, because that code had the table always showing the first 10 transactions made. So, once again, for the people looking for the final answers to the problems I'm asking, here is the result:


<%
rs.Open "Select top 10 IfAmount, GivenTo, Date from Transactions WHERE ComingFrom = '" & strUserName & "' and IsNull(IfItemID)=True order by TransID desc", conn
Dim IfAmount
Dim GivenTo
Dim DateGiven
%>
<%
rsData = rs.GetRows

For i = 0 to ubound(rsData, 2)
  IfAmount = rsData(0, i)
  GivenTo  = rsData(1, i)
  DateGiven= rsData(2, i)

  Response.Write("You gave " & IfAmount & " Rupees to " & GivenTo & " on " & DateGiven & ".<br><br>")

Next
%>
<%
rs.close
%>

And thanks again for the assistance, you roxors.

If something goes wrong, find the source of the problem and break it's legs.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.2 seconds. Powered By: Snitz Forums 2000 Version 3.4.07