I want to make just 1 call to the database! not 3! Support
GetUser1
SELECT * From Users WHERE ID = 1
GetUser2
SELECT * From Users WHERE ID = 2
GetUser3
SELECT * From Users WHERE ID = 3
Click Read More to see what ive tried so far!
I make a recordsset called GetUsers
SELECT * From Users
ID    |    Name
-----------------
 1    |  Will
 2    |  John
 3    |  Mark
All good so far, Then I want to be able to write the results to the page, but I want to pick wich ID to write to the screen, when I do this it just displays the first one:
<%=(GetUsers.Fields.Item("Name").Value)%>
So I quickly learnt to use a repeat region
       <% 
While ((Repeat2__numRows <> 0) AND (NOT GetUsers.EOF)) 
%> 
<%=(GetUsers.Fields.Item("Name").Value)%>
       <% 
  repeat2__index="Repeat2__index"+1
  repeat2__numrows="Repeat2__numRows"-1
  GetUsers.MoveNext()
Wend
%>
But I get all of them, so I tried the advanced Adv Conditional Region, it does what I want, but I can only use it once on the page.
        <% 
While ((Repeat2__numRows <> 0) AND (NOT GetArt.EOF)) 
%>   
<% if GetUsers.Fields.Item("ID").Value = "2" then ' Adv Conditional Region %>
<%=(GetUsers.Fields.Item("Name").Value)%>
<% end if ' GetArt.Fields.Item("ID").Value = "2" %>
<% 
  repeat2__index="Repeat2__index"+1
  repeat2__numrows="Repeat2__numRows"-1
  GetUsers.MoveNext()
Wend
%>
So, at the moment Im making 3 recordsets, but Im sure its wrong to go back to the database 3 times to do this!
GetUser1
SELECT * From Users WHERE ID = 1
GetUser2
SELECT * From Users WHERE ID = 2
GetUser3
SELECT * From Users WHERE ID = 3
Any ideas anyone?
Thanks in adavance
Will
Comments
WHERE IN Clause
Using the WHERE IN clause let's you return selected records.
SELECT *
FROM Users
WHERE ID IN (1,2,3)
You must me logged in to write a comment.