If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > Select top 10 info from two Tables

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-20-04, 06:50
inkarpathos inkarpathos is offline
Registered User
 
Join Date: Nov 2004
Posts: 2
Select top 10 info from two Tables

Can someone please help me, I am very new at this?

I have a photo program written in ASP with an Access database. I have found a script that goes in a table named xlaAIGcategories and selects the last 10 categories that were created. It then lits the categories name with a link to a particular part of the program.

I would like to also place a photo with the category name (the first photo in that category), but it is located in a different table.

In the second table there are fields that have the same category id number “Categoryid”.

I have two tables in the database.

The first one is named xlaAIGcategories the second one is named xlaAIGimages.

The first one has the following fields of interest.
Categoryid, catname, catpath which are unique. Not two field have the same value.

In the second table the fields of interests are Categoryid and imagefile, which are not unigue.

My script is as follows:

<% Dim rsLastestPostsModPhoto
Dim adoLastestPostsModConPhoto
Dim strLastestPostsModConPhoto
Dim strSQLLastsPostsModPhoto

Dim strLastestPostsModTopicSubjectPhoto
Dim strLastestPostsModForumPathPhoto
Dim intLastestPostsTotalPhoto

'The path to the forum
strLastestPostsModForumPathPhoto = "../cgi-bin/Gallery/"

'How many new topics to show
intLastestPostsTotalPhoto = 10


'Default connection
strLastestPostsModConPhoto = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("../cgi-bin/Gallery/db/absoluteig.mdb")


Set adoLastestPostsModConPhoto = Server.CreateObject("ADODB.Connection")
adoLastestPostsModConPhoto.Open strLastestPostsModConPhoto

Set rsLastestPostsModPhoto = Server.CreateObject("ADODB.Recordset")

strSQLLastsPostsModPhoto = "SELECT top 10 Categoryid, catname From xlaAIGcategories ORDER BY Categoryid DESC"


rsLastestPostsModPhoto.Open strSQLLastsPostsModPhoto, adoLastestPostsModConPhoto

If rsLastestPostsModPhoto.EOF Then
Response.Write "<span class=""smltext"">No New Photos Made</span>"
Else

Do while NOT rsLastestPostsModPhoto.EOF
strLastestPostsModTopicSubjectPhoto = rsLastestPostsModPhoto("catname")

Response.Write("<a href=""" & strLastestPostsModForumPathPhoto & "gallery.asp?categoryid=" & rsLastestPostsModPhoto("Categoryid") & " "">" & strLastestPostsModTopicSubjectPhoto & "</a>")

Response.Write("<br>")

rsLastestPostsModPhoto.MoveNext
If NOT rsLastestPostsModPhoto.EOF Then Response.Write("<br>")
Loop

End If

'Reset Server Objects
rsLastestPostsModPhoto.Close
Set rsLastestPostsModPhoto = Nothing
adoLastestPostsModConPhoto.Close
Set adoLastestPostsModConPhoto = Nothing
%>
Reply With Quote
  #2 (permalink)  
Old 11-22-04, 14:57
Seppuku Seppuku is offline
Useless...
 
Join Date: Jul 2003
Location: SoCal
Posts: 721
Try this:

SELECT top 10 Categoryid, catname, (SELECT top 1 imagefile FROM xlaAIGimages img WHERE cat.CategoryID = img.Categoryid) AS imagefile From xlaAIGcategories cat ORDER BY Categoryid DESC
__________________
That which does not kill me postpones the inevitable.
Reply With Quote
  #3 (permalink)  
Old 11-26-04, 15:34
inkarpathos inkarpathos is offline
Registered User
 
Join Date: Nov 2004
Posts: 2
It works Great

Thank You,

You saved me alot of time!!!!!!!!!!!!!!!!!!!!!!!!!!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On