How do I get a search to show me more than one result.

Discussion in 'ASP General' started by technoplonker, Jan 19, 2004.

  1. I am carrying out a search on an MS Access 2000 db from within a page.
    I know that there is more than one result to be displayed, but I can't
    get the code to loop to the second result onwards. This is the code.

    I hope it's not too big, as I don't want to end up with a thick ear.

    <div id="masterdiv">
    <%

    Dim cn
    Dim rs
    Dim theVariable
    Dim rsSearchResult 'database Recordset Variable
    Dim sarySearchWord 'Holds the keywords for the URL
    Dim strSearchKeywords 'Holds the keywords to be searched
    menuNum = 1
    Set CN=CreateObject("ADODB.COnnection")
    CN.Open strCon

    Set RS=CN.Execute("SELECT nav FROM Nav")
    Do While not RS.EOF
    theVariable=RS.Fields("Nav")
    Response.Write "<div class=""menutitle""
    onclick=""SwitchMenu('sub" & menuNum & "')"">"
    Response.Write theVariable & "</div>"
    Response.Write "<span class=""submenu"" id=""sub" & menuNum &
    """>"


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

    strSearchKeywords = Trim(Request.QueryString("search"))

    sarySearchWord = Split(Trim(strSearchKeywords), " ")

    strSQL = "SELECT Pages.* FROM Pages "

    strSQL = strSQL & "WHERE cat LIKE '%" & theVariable & "%'"


    rsSearchResult.Open strSQL, strCon

    Response.Write vbCrLf & vbCrLf
    Response.Write vbCrLf & " <a href=""" & rsSearchResult("cat") & """>"
    & rsSearchResult("title") & "</a>"
    Response.Write vbCrLf & " </span>"

    menuNum = menuNum+1
    RS.MoveNext
    Loop
    Set RS=nothing
    CN.Close
    Set CN=nothing
    Set SearchResult=nothing
    %>

    </div>

    Thanks in advance

    TP
    technoplonker, Jan 19, 2004
    #1
    1. Advertising

  2. technoplonker

    Alex Goodey Guest

    you loop on the RS recordset but not the rsSearchResult record set, try
    using a Do While like you already have on both Record Sets
    "technoplonker" <> wrote in message
    news:...
    > I am carrying out a search on an MS Access 2000 db from within a page.
    > I know that there is more than one result to be displayed, but I can't
    > get the code to loop to the second result onwards. This is the code.
    >
    > I hope it's not too big, as I don't want to end up with a thick ear.
    >
    > <div id="masterdiv">
    > <%
    >
    > Dim cn
    > Dim rs
    > Dim theVariable
    > Dim rsSearchResult 'database Recordset Variable
    > Dim sarySearchWord 'Holds the keywords for the URL
    > Dim strSearchKeywords 'Holds the keywords to be searched
    > menuNum = 1
    > Set CN=CreateObject("ADODB.COnnection")
    > CN.Open strCon
    >
    > Set RS=CN.Execute("SELECT nav FROM Nav")
    > Do While not RS.EOF
    > theVariable=RS.Fields("Nav")
    > Response.Write "<div class=""menutitle""
    > onclick=""SwitchMenu('sub" & menuNum & "')"">"
    > Response.Write theVariable & "</div>"
    > Response.Write "<span class=""submenu"" id=""sub" & menuNum &
    > """>"
    >
    >
    > Set rsSearchResult = Server.CreateObject("ADODB.Recordset")
    >
    > strSearchKeywords = Trim(Request.QueryString("search"))
    >
    > sarySearchWord = Split(Trim(strSearchKeywords), " ")
    >
    > strSQL = "SELECT Pages.* FROM Pages "
    >
    > strSQL = strSQL & "WHERE cat LIKE '%" & theVariable & "%'"
    >
    >
    > rsSearchResult.Open strSQL, strCon
    >
    > Response.Write vbCrLf & vbCrLf
    > Response.Write vbCrLf & " <a href=""" & rsSearchResult("cat") & """>"
    > & rsSearchResult("title") & "</a>"
    > Response.Write vbCrLf & " </span>"
    >
    > menuNum = menuNum+1
    > RS.MoveNext
    > Loop
    > Set RS=nothing
    > CN.Close
    > Set CN=nothing
    > Set SearchResult=nothing
    > %>
    >
    > </div>
    >
    > Thanks in advance
    >
    > TP
    Alex Goodey, Jan 19, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Merciadri Luca
    Replies:
    4
    Views:
    802
  2. Tim Hunter
    Replies:
    0
    Views:
    91
    Tim Hunter
    Dec 18, 2003
  3. Michael Tan
    Replies:
    32
    Views:
    940
    Ara.T.Howard
    Jul 21, 2005
  4. Steven D'Aprano
    Replies:
    0
    Views:
    81
    Steven D'Aprano
    Dec 23, 2013
  5. Replies:
    3
    Views:
    74
    Gary Herron
    Dec 23, 2013
Loading...

Share This Page