Before I throw my new expensive laptop out of the window!
I'm stuck on getting my joins right with the correct amount in a column count. After speaking with someone a few weeks back, they suggested I redesigned my database to use more tables of info. Before I had 1 table for image information, now I have 9 and it's getting very, very confusing... especially as I don't know much about joins...!
I am using ASP, MySQL, IIS and VBScript.
My 9 tables consist of:
Images
ImageID, Height, Width, DateCreated, Orientation
Keywords
KeywordID
Keyword
ImageKeyword
ImageId
KeywordID
People
PeopleID
People
ImagePeople
ImageID
PeopleID
Events
EventID
EventName
ImageEvent
ImageID
EventID
Photographers
PhotographerID
FirstName
LastName
Byline
ImagePhotograph er
ImageID
PhotographerID
My code is as follows:
Hopefully, if it makes sense to you, it should display a list of events that matches the search criteria stored in the session variables.
As an example, If Victoria Beckham was at the Oscar Awards 2008 and MTV Awards 2007 and I searched for her name, it would show...
18 FEB 08
Oscar Awards 2008 (105 Images)
Los Angeles, USA.
07 JUL 07
MTV Awards 2008 (65 Images)
Berlin, Germany.
It seems pretty simple but I am so confused and behind with the project its starting to hurt a bit.... I know my GROUP BY clause is wrong because of the amount the COUNT is returning, and also maybe joining the wrong columns together.
Any chance I can get some help with the SQL string...? If I see the correct version compared to my crap version, I think I will learn from it quickly. Quicker than the 26 hours I've put into this problem already...!
Many thanks in advance, from a stressed amateur...
I'm stuck on getting my joins right with the correct amount in a column count. After speaking with someone a few weeks back, they suggested I redesigned my database to use more tables of info. Before I had 1 table for image information, now I have 9 and it's getting very, very confusing... especially as I don't know much about joins...!
I am using ASP, MySQL, IIS and VBScript.
My 9 tables consist of:
Images
ImageID, Height, Width, DateCreated, Orientation
Keywords
KeywordID
Keyword
ImageKeyword
ImageId
KeywordID
People
PeopleID
People
ImagePeople
ImageID
PeopleID
Events
EventID
EventName
ImageEvent
ImageID
EventID
Photographers
PhotographerID
FirstName
LastName
Byline
ImagePhotograph er
ImageID
PhotographerID
My code is as follows:
Code:
<td background="images/navigation_tabs/search-middle.gif" style="padding-top:5px;">
<%
RefineSQL = " SELECT E.EventName , E.EventID , I.City , I.Country , I.DateCreated , " _
& "IE.ImageID , I.ImageID , P.PeopleID , IE.EventID , Count(E.EventName) AS TotalEvent " _
& "FROM images AS I , imagepeople AS IP , people AS P , events AS E , imageevent AS IE " _
& "WHERE P.PeopleID = IP.PeopleID AND IP.ImageID = I.ImageID AND E.EventID = IE.EventID "
If (Session("event") & "") <> "" Then
RefineSQL = RefineSQL & "AND E.EventID = '"&Session("event")&"' "
End If
If (Session("people") & "") <> "" Then
RefineSQL = RefineSQL & "AND P.PeopleID = '"&Session("people")&"' "
End If
If (Session("location") & "") <> "" Then
RefineSQL = RefineSQL & "AND I.City = '"&Session("location")&"' "
End If
If (Session("keyword") & "") <> "" Then
RefineSQL = RefineSQL & "AND K.KeywordID = '"&Session("keyword")&"' "
End If
If (Session("orientation") & "") <> "" Then
RefineSQL = RefineSQL & "AND I.Orientation = '"&Session("orientation")&"' "
End If
If (Session("composition") & "") <> "" Then
RefineSQL = RefineSQL & "AND K.Keyword = '"&Session("composition")&"' "
End If
RefineSQL = RefineSQL & "GROUP BY E.EventName ORDER BY I.DateCreated DESC LIMIT 8"
Rs.Open RefineSQL
Counter = 0
Do until Rs.EOF
Counter = Counter + 1
Response.Write "<TABLE WIDTH=""100%"">"
Response.Write "<TR>"
Response.Write "<TD STYLE=""padding-left:8px;"" CLASS=""content_lightgrey_small"">"
ExpandShortDate(Rs("DateCreated"))
Response.Write "</TD>"
Response.Write "</TR>"
Response.Write "<TR>"
Response.Write "<TD STYLE=""padding-left:8px;"" CLASS=""content_small"">"
Response.Write "<A HREF=""expressResults.asp?side=yes&event="&Rs("EventID")&""" " _
& "CLASS=""grey_link_small"">"&Replace(Rs("EventName"),"*","'")&"</A> ("&Rs("TotalEvent")&")"
Response.Write "</TD>"
Response.Write "</TR>"
Response.Write "<TR>"
Response.Write "<TD STYLE=""padding-left:8px;"" CLASS=""content_small"">"
Response.Write Rs("City")&", "&Rs("Country")
Response.Write "</TD>"
Response.Write "</TR>"
Response.Write "<TR>"
Response.Write "<TD STYLE=""padding-left:8px;"" CLASS=""content_lightgrey_small"">"
Response.Write "<IMG SRC=""images/shim.gif"" HEIGHT=""3"">"
Response.Write "</TD>"
Response.Write "</TR>"
Response.Write "</TABLE>"
Rs.MoveNext
Loop
Rs.Close
%>
</td>
Hopefully, if it makes sense to you, it should display a list of events that matches the search criteria stored in the session variables.
As an example, If Victoria Beckham was at the Oscar Awards 2008 and MTV Awards 2007 and I searched for her name, it would show...
18 FEB 08
Oscar Awards 2008 (105 Images)
Los Angeles, USA.
07 JUL 07
MTV Awards 2008 (65 Images)
Berlin, Germany.
It seems pretty simple but I am so confused and behind with the project its starting to hurt a bit.... I know my GROUP BY clause is wrong because of the amount the COUNT is returning, and also maybe joining the wrong columns together.
Any chance I can get some help with the SQL string...? If I see the correct version compared to my crap version, I think I will learn from it quickly. Quicker than the 26 hours I've put into this problem already...!
Many thanks in advance, from a stressed amateur...
Comment