Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 23rd, 2003, 02:20 PM
Registered User
 
Join Date: Jul 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Displaying Multiple Results

I have a ASP Web results page working with an Access database. What I want to do now is return results but break them down into catagories such as:

>>>

TITLE 1

1
2
3

TITLE 2

4
5
6
7

TITLE 3

8
9
10

<<<

Right now I can show the results for Title 1 & Title 2 but not Title 3. I have put that into a function (getMoreStates) but it does not work properly.

Here is the code that I have for the currently. Where or how do I adjust them to return the new desired results?

>>>

...

strSearch = Request.QueryString("search")
strSearch = Replace(strSearch, "'", "''")

Get all the items in the passed category

if u_id <> "" then
    strSQL = "select * from REFERRAL WHERE NCOMP_NO =" & u_id
else
    strSQL = "select * from REFERRAL WHERE STATE = '" & Replace(strSearch, "'", "''") & "' " & "ORDER BY TRAINCENTR DESC, CITY;"
    tempSQL = strSQL
end if

Set RS1 = conn.Execute( strSQL )
Set NCOMP_NO = RS1("NCOMP_NO")
Set STSEARCH = RS1("STATE")

scriptresponder = "DisplayTrainer.asp"

Function getTravelStates( NCOMP_NO )
    Dim SQL, RSS, list
    SQL = "SELECT ST.STATE FROM REFSTATE AS ST, REFERRAL AS MM WHERE ST.NCOMP_NO =" & NCOMP_NO & " AND MM.NCOMP_NO =" & NCOMP_NO & " ORDER BY ST.STATE"
    Set RSS = conn.Execute( SQL )

    list = RSS.GetString( , , "", "," )
    RSS.Close
    getTravelStates = Left( list, LEN(list)-1 )
End Function

If Replace(strSearch, "'", "''") <> tempSQL Then
    listOfStates = ""
else
    listOfStates = getTravelStates( NCOMP_NO )
End if

Function getMoreStates(RS)
    Dim sSQL, RSS2
    If not objRec.EOF Then
    sSQL = "SELECT * FROM REFSTATE WHERE STATE =" & strSearch
    objRec.MoveNext
    End if
    Set RSS2 = conn.Execute( sSQL )

    RSS2.Close
End Function

...

objREC.Open strSQL, Conn, adOpenForwardOnly, adLockReadOnly, adCmdText

numpages = objRec.PageCount
numrecs = objRec.RecordCount

If mypage > numpages Then mypage = numpages
If mypage < 1 Then mypage = 1

    if not objRec.EOF then

objRec.AbsolutePage = mypage

if u_id <> "" then

    Response.Write "<table border='0' cellspacing='0' cellpadding='3'><tr><td valign='top'><div class='smallcopy' align='top'><b>Organization: </b>" & objRec.Fields("COMPANY") & "<br><b>Address: </b>" & objRec.Fields("ADDRESS") & "<br><b>City: </b>" & objRec.Fields("CITY") & "<br><b>State: </b>" & objRec.Fields("STATE") & "<br><b>Zip Code: </b>" & objRec.Fields("ZIP") & "</div></td><td valign='top'><div class='smallcopy' align='top'><b>Phone Number: </b>" & objRec.Fields("PHONE") & "<br><b>Email Address: </b><a href='mailto:" & objRec.Fields("EMAIL") & "'>" & objRec.Fields("EMAIL") & "</a>" & "<br><b>Programs Taught: </b><br>" & programs(objRec) & "<br><b>Will Travel To:</b><br>" & listOfStates & "</div></td></tr><tr><td>&nbsp;</td></tr></table>"

else

    Response.Write("<div class='maincopy' align='top'>Search found " & numrecs & " total records. Displaying page " & mypage & " of " & numpages & ".</div><br>")

If objRec.Fields("TRAINCENTR") = "N" Then

    Response.Write "<table border='0' cellspacing='0' cellpadding='3'><tr><td colspan='3' class='maincopy'><b>National Training Centers</b></td></tr><tr class='maincopy'><th align='left'>[u]City</u></th><th align='left'>[u]Company</u></th><th align='left'>[u]Programs Taught</u></th></tr>"

    Dim iin
    For iin = 1 To pagesize

        If NOT objRec.EOF AND objRec.Fields("TRAINCENTR") = "N" Then
        trainnumber = trainnumber + 1

    my_link = scriptresponder & "?u_id=" & objRec.fields("NCOMP_NO")

            Response.Write "<tr><td><div class='smallcopy' align='top'>" & "<a href='" & my_link & "'>" & objRec.Fields("CITY") & "</a>" & "</div></td>" & "<td><div class='smallcopy' align='top'>" & "<a href='" & my_link & "'>" & objRec.Fields("COMPANY") & "</a></div></td>" & "<td><div class='smallcopy' align='top'>" & programs(objRec) & "</div></td></tr>"
            objRec.MoveNext
        End If
    Next

    Response.Write "<tr><td>&nbsp;</td></tr></table>"

End if

    Response.Write "<table border='0' cellspacing='0' cellpadding='3'><tr><td colspan='3' class='maincopy'><b>Training Organizations</b></td></tr><tr class='maincopy'><th align='left'>[u]City</u></th><th align='left'>[u]Company</u></th><th align='left'>[u]Programs Taught</u></th></tr>"

    Dim i
    For i = 1 To pagesize - trainnumber
    mmstate = i
        If NOT objRec.EOF Then

    my_link = scriptresponder & "?u_id=" & objRec.fields("NCOMP_NO")

            Response.Write "<tr><td><div class='smallcopy' align='top'>" & "<a href='" & my_link & "'>" & objRec.Fields("CITY") & "</a>" & "</div></td>" & "<td><div class='smallcopy' align='top'>" & "<a href='" & my_link & "'>" & objRec.Fields("COMPANY") & "</a></div></td>" & "<td><div class='smallcopy' align='top'>" & programs(objRec) & "</div></td></tr>"
            objRec.MoveNext
        End If
    Next

    Response.Write "<tr><td>&nbsp;</td></tr></table>"

If getMoreStates(objRec) <> "" Then

    Response.Write "<table border='0' cellspacing='0' cellpadding='3'><tr><td colspan='3' class='maincopy'><b>Training Organizations</b></td></tr><tr class='maincopy'><th align='left'>[u]City</u></th><th align='left'>[u]Company</u></th><th align='left'>[u]Programs Taught</u></th></tr>"

    Dim iim
    For iim = 1 To pagesize - mmstate

        If NOT objRec.EOF AND getMoreStates(objRec) Then

    my_link = scriptresponder & "?u_id=" & objRec.fields("NCOMP_NO")

            Response.Write "<tr><td><div class='smallcopy' align='top'>" & "<a href='" & my_link & "'>" & objRec.Fields("CITY") & "</a>" & "</div></td>" & "<td><div class='smallcopy' align='top'>" & "<a href='" & my_link & "'>" & objRec.Fields("COMPANY") & "</a></div></td>" & "<td><div class='smallcopy' align='top'>" & programs(objRec) & "</div></td></tr>"
            objRec.MoveNext
        End If
    Next

    Response.Write "<tr><td>&nbsp;</td></tr></table>"

End if

end if

>>>

Any ideas or assistance would be helpful.
Thanks.
 
Old July 24th, 2003, 04:45 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 158
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to NotNowJohn
Default

Hi there,
I have not read whole text, but I notice that objRec object is not defined in the body of the function getMoreStates, strSearch variable is not defined, too, and SQL statement is
sSQL = "SELECT * FROM REFSTATE WHERE STATE=''" and there is no records after the statement has been executed. Check this function with more patience. If you need help in the func's body implementation, just let me know.
Regards,
NNJ

...but the Soon is eclipsed by the Moon
 
Old July 24th, 2003, 12:41 PM
Registered User
 
Join Date: Jul 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yea, I could use help to figure out the solution to this.

As for the stSearch, it is defined near the top. It comes from a previous form for the State to be searched. So, if the reqested State search is CT, then strSearch would be CT and the SQL statement should read:

sSQL = "SELECT * FROM REFSTATE WHERE STATE =CT"

If you see that that is not the case, could you please help me clarify that?

The objRec is defined in the line:

objREC.Open strSQL, Conn, adOpenForwardOnly, adLockReadOnly, adCmdText

Should this be different? What should it be?

Thanks.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Display results from a database on multiple pages osemollie PHP How-To 1 January 27th, 2006 07:58 AM
Displaying a number of results fogofogo XSLT 2 November 22nd, 2005 12:18 PM
Mysql Sorting results from multiple tables dcb22 SQL Language 8 October 25th, 2004 10:57 AM
Display results from multiple tables Librarian Classic ASP Databases 6 July 6th, 2004 11:28 PM
Getting results from Select Multiple HTML tag dpjoff PHP How-To 9 February 2nd, 2004 04:03 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.