taylorantone
MIS
I'll try to say this in as few words as possible so it's not any more confusing than it currently is.
I have a database in Access with a table for DVD's and a table for Genres. Each of these tables has a one-to-many relationship with a linking table--I needed a way for a movie to be assigned to multiple genres, while also allowing a genre to be assigned to multiple movies. The relevant fields are laid out as follows:
tblDVD
- dvdID (autonumber--related one-to-many with dvdID in the next table)
- title
tblDVDGenres
- dvdID
- genreID
tblGenres
- genreID (autonumber--related one-to-many with genreID in the table above)
- genre
There are the three tables essentially givin me the many-to-many resulting relationship that I need.
Now, I have a current ASP page that lets you choose a genre and a sorting field (also whether to sort asc or desc) from a database-populated drop-down and the table lists the DVD's that are assigned to that genre. Here's the current SQL statement:
Here's a link to the current page in case that helps me explain this any better:
Here's what I'm trying to do. As the query loops through the recordset and displays each record, I want to have a field called "genres" pull in all of the related genres to the DVD on the current record and separates them with a comma.
Just taking a stab at it, I'd think it would need to put something like this into the data for the "genres" field (pseudo-code below--if I knew the actual code I wouldn't be posting ):
Anyone know how to get this work? I know there's a way, but I'm not a very advanced ASP guy so I run into walls pretty easily.
Thanks!!
UPDATE!!!!!!!!!!!!!!!!!!!
Man, I'm right on the edge of getting this, but there's some small thing I'm doing wrong. Here are the changes I made:
- created a new query in Access with just the information I need
- created a variable called "vartitle"
- created another recordset object for this new query
- here's the SQL statement for it:
- the field that writes the title of each DVD now looks like this:
I had the variable initialized first and then used the variable to write the title to make sure that the variable was initializing successfully--and it is
- the loop for the genres field looks like this:
Now, I've managed to remove all of the errors I was receiving and the search pulls up the matching records, but no genres are being written into the genres field. I don't get it. Like I said, I feel like I'm right on the edge of getting this to work, but there's something stupid I'm missing or doing wrong.
Here's what's happening:
Anyone out there with a decent ASP/SQL background to give me an idea?
I have a database in Access with a table for DVD's and a table for Genres. Each of these tables has a one-to-many relationship with a linking table--I needed a way for a movie to be assigned to multiple genres, while also allowing a genre to be assigned to multiple movies. The relevant fields are laid out as follows:
tblDVD
- dvdID (autonumber--related one-to-many with dvdID in the next table)
- title
tblDVDGenres
- dvdID
- genreID
tblGenres
- genreID (autonumber--related one-to-many with genreID in the table above)
- genre
There are the three tables essentially givin me the many-to-many resulting relationship that I need.
Now, I have a current ASP page that lets you choose a genre and a sorting field (also whether to sort asc or desc) from a database-populated drop-down and the table lists the DVD's that are assigned to that genre. Here's the current SQL statement:
Code:
sqlqrygenre = "SELECT tblGenres.genre, tblDVD.title, tblDVD.notes, tblDVD.genres, tblDVD.year, IIf([borrowerID]=28,'Yes','No') AS [in] FROM tblGenres INNER JOIN (tblDVD INNER JOIN tblDVDGenre ON tblDVD.dvdID = tblDVDGenre.dvdID) ON tblGenres.genreID = tblDVDGenre.genreID WHERE genre = '" & Request.Form("selgenre") & "' " & Request.Form("sort") & " " & Request.Form("order") & ";"
Here's a link to the current page in case that helps me explain this any better:
Here's what I'm trying to do. As the query loops through the recordset and displays each record, I want to have a field called "genres" pull in all of the related genres to the DVD on the current record and separates them with a comma.
Just taking a stab at it, I'd think it would need to put something like this into the data for the "genres" field (pseudo-code below--if I knew the actual code I wouldn't be posting ):
Code:
Do While NOT oRSqrygenre.EOF
Response.Write oRSqrygenre("genre") & ", "
oRSqrygenre.MoveNext
Loop
Anyone know how to get this work? I know there's a way, but I'm not a very advanced ASP guy so I run into walls pretty easily.
Thanks!!
UPDATE!!!!!!!!!!!!!!!!!!!
Man, I'm right on the edge of getting this, but there's some small thing I'm doing wrong. Here are the changes I made:
- created a new query in Access with just the information I need
- created a variable called "vartitle"
- created another recordset object for this new query
- here's the SQL statement for it:
Code:
sqlgenresperdvd = "SELECT tblDVD.title, tblDVD.notes, tblDVD.year, tblDVD.borrowerID, tblDVDGenre.genreID FROM tblDVD INNER JOIN tblDVDGenre ON tblDVD.dvdID = tblDVDGenre.dvdID WHERE tblDVD.title = '" & vartitle & "';"
- the field that writes the title of each DVD now looks like this:
Code:
<% vartitle = oRSqrygenre("title")%><%=vartitle%>
I had the variable initialized first and then used the variable to write the title to make sure that the variable was initializing successfully--and it is
- the loop for the genres field looks like this:
Code:
<%
Do While NOT oRSgenresperdvd.EOF
Response.Write oRSgenresperdvd("genreID") & ", "
oRSgenresperdvd.MoveNext
Loop
%>
Now, I've managed to remove all of the errors I was receiving and the search pulls up the matching records, but no genres are being written into the genres field. I don't get it. Like I said, I feel like I'm right on the edge of getting this to work, but there's something stupid I'm missing or doing wrong.
Here's what's happening:
Anyone out there with a decent ASP/SQL background to give me an idea?