Filter column data on output

Discussion in 'Databases' started by raith, May 31, 2007.

  1. #1
    I am trying to figure out a way to filter output results based on a query on two different tables. The unique thing they share is a column called ProgramID. I am able to call the recordset, read the data from them, loop through the recordset and display that data just fine. However I'm having some trouble filtering the links with the names in the output. Currently the output shows single names and single links just fine but when there are multiple names with multiple links, the output shows all of the links (which represent all the names) under "each" name.

    It should read each name "but" with only the link associated with that one name and not all of the links. Example:

    Greg Atkinson food writer, chef and regular contributor to the Cooking Klatch...

    Related Links:
    * Brasa
    * Greg Atkinson
    * Tom Douglas Restaurants

    Greg's name should have "only" the Greg Atkinson link listed under his name. Not all three links.

    The question is should I tweak my ASP code or my SQL code to make this happen?

    Below is my SQL code for your reference:

    <%
    set con = Server.CreateObject("ADODB.Connection")
    con.Open "File Name=E:\webservice\Company\Company.UDL"
    set rs = Server.CreateObject("ADODB.Recordset")
    
    id=request.querystring("id")
    
    IF id <> "" then id=id else id="9726" end if  'This is a default record
    
    '  This will return records
    strSQL = "SELECT DISTINCT GuestName, GuestDescription, URL, Description FROM T_ProgramGuests tpg LEFT JOIN T_ProgramLinks tpl ON tpl.ProgramID = tpg.programID WHERE (tpg.ProgramID = " & id & ")" 
    
    rs.Open strSQL,con
    
    previousGuestName = ""
    
    While Not RS.Eof
    	'  Only output guest details if this record has a different guest name to the previous one
    	if previousGuestName <> cStr(rs("guestName")) then
    	  response.write "<br />"
    		response.write "<strong>" & rs("GuestName") & "</strong>"  & rs("GuestDescription") & "<br /><br />Related Links:<br />"
    		previousGuestName = cStr(rs("guestName"))
    	end if
    	
    	'  Always output the related links though
    	response.write "<li class=""basic""><A HREF='" & trim(rs("URL")) & "'>" & trim(rs("Description")) & "</A></li>"
    	RS.MoveNext
    Wend
    
    recProgram.Close
    con.Close
    set recProgram = nothing
    set con = nothing
    %>
    Code (markup):
    The design layout of the two tables are (in order)

    Guests Table: GuestID, ProgramID, GuestName, GuestDescription

    Links Table: LinkID, ProgramID, URL, Description

    I'm pulling my hair out on this cause I'm so close to being done. Any help is greatly appreciated. :eek:
     
    raith, May 31, 2007 IP
  2. raith

    raith Peon

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I was just thinking maybe the key to what I'm wanting is the LinkID. You see Greg has a LinkID of #10 which is the Greg Atkinson link in the table. I've tried tweaking the query to account for this in QA but with not much luck.

    If I know this person has a unique LinkID associated with his URL then all I should have to do is account for this somehow in the query or in the display code. Though it might be easier making those adjustments in the query.

    Thoughts anyone?
     
    raith, May 31, 2007 IP
  3. raith

    raith Peon

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I've tried adjusting the display code to account for LinkID but still not getting the output I need. My thinking is that if I know that LinkID #10 is distinct to one person then I would need to add a nested IF Then.

    
    if LinkID <> cStr(rs(10) )then
    	response.write "<li class=""basic""><A HREF='" & trim(rs("URL")) & "'>" & trim(rs("Description")) & "</A></li>"
      end if
    
    Code (markup):
    This merely repeats the links.
     
    raith, May 31, 2007 IP