Forum Moderators: open

Message Too Old, No Replies

problem with vbscript that won't stop looping

         

KRMwebdesign

3:35 pm on Oct 13, 2009 (gmt 0)

10+ Year Member




Just wondering if anyone can see any issues with this script. It keeps looping even after it has shown all the data and then my browser crashes. I'm not sure what the problem is as it was working fine before today.

<%
do while NOT rsOuter.EOF
if counter1 mod 2 = 0 then bg="#990000"
else
bg="#660000"
end if
%>

My Data here

<%
counter1 = counter1 + 1
rsOuter.MoveNext
loop
%>

KRMwebdesign

4:25 pm on Oct 13, 2009 (gmt 0)

10+ Year Member



I think it could actually be the SQL statement that I'm using:

<%
MyID = request.queryString("ID")

if ( MyID <>"" ) then
MyID = replace(MyID, "'","''")
end if
%>

sql="Select * From Table1, Table2 WHERE Table2.t2ID = '" & MyID & "' ORDER BY UploadID DESC"

Both t2ID and ID are 'number' fields in an access database.

I've tried writing it as:
Select * From Table1 INNER JOIN Table2 on Table1.ID = Table2.t2ID WHERE Table2.t2ID = '" & getValue & "'"

But nothing shows up this way :(

Any help would be appreciated.

marcel

5:05 am on Oct 14, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm not sure what the problem is as it was working fine before today.

Did you change anything at all? (extra data imported for example)

Have you tried using your SQL statement directly on the database?

KRMwebdesign

9:48 am on Oct 14, 2009 (gmt 0)

10+ Year Member



I think this was due to my SQL statement. I changed the SQL statement as I had converted my SQL server database into an Access database for testing purposes. The SQL statement didn't seem to work when I wrote it as:

Select * From Table1 INNER JOIN Table2 on Table1.ID = Table2.t2ID WHERE Table2.t2ID = '" & MyID & "'"

so I tried writing it as

Select * From Table1, Table2 WHERE Table2.t2ID = '" & MyID & "'"
(for those with questions here is the VBscript I used to get the MyID variable)

<%
MyID = request.queryString("ID")

if ( MyID <>"" ) then
MyID = replace(MyID, "'","''")
end if
%>

But when I used this statement the repeat regions (I tried many) just kept repeating and crashing my browser. I've since changed it back to the first statement and it seems to be working now. The repeat regions too.

I think I may encounter some issues with some of my pages though. Does anyone have an SQL statement I may be able to use that will work with my Access database and with the repeat regions? It's trial and error I know but I don't have a lot of time to finish this :(

Thanks for all your help.

KRMwebdesign

10:33 am on Oct 14, 2009 (gmt 0)

10+ Year Member



I keep getting a "Type mismatch in query expression" error when I use this SQL statement:

Select * From Table1 INNER JOIN Table2 on Table1.ID = Table2.t2ID WHERE Table2.t2ID = '" & MyID & "'"

But my Repeat Regions crash when I use this SQL statement:
Select * From Table1, Table2 WHERE Table2.t2ID = '" & MyID & "'"

I wonder does anyone have some sort of solution for me? I find it odd that there is a "Type mismatch" for the first select statement but not for the second. I take it the issue is not in the database then and rather my variables perhaps?

My Joins!? Is it the joins? It's my joins isn't it? Should I be using some sort of outer join? Basically Table1 is a member profile and Table2 is a comments table. So users are leaving comments on the member profile and the data for that member is contained in Table1. Should that be an LEFT OUTER JOIN? I'll try it and let you know if my computer explodes or if it works. I'm running out of computers here though! :(

I know I'm rubbish at programming by the way.

marcel

11:35 am on Oct 14, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm terrible with joins myself, I usually use the GUI for building these kind of queries and then adapt them slightly to fit my needs. Have you tried doing that?

I set up a simple DB like this:
User
Id int
Name varchar
Comment
Id int
UserId int
Comment varchar

If I want all of the comments for the User Id '1' then I would need the following:

SELECT Comment.Id, _Comment.UserId, Comment.Comment
FROM Comment INNER JOIN
User ON Comment.UserId = User.Id
WHERE (User.Id = 1)