Welcome to Dream.In.Code
Become an Expert!

Join 149,504 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,370 people online right now. Registration is fast and FREE... Join Now!




VBScript recordset help

2 Pages V  1 2 >  
Reply to this topicStart new topic

VBScript recordset help, VBScript recordset help

cool263
30 Jul, 2007 - 09:15 AM
Post #1

New D.I.C Head
*

Joined: 17 Jul, 2007
Posts: 19


My Contributions
I'm building a web page that has a list of different realestate locations and pulls this info from a database. The user can filter and view the properties by location. My problem is, is that I would like to display a header above the first location, but not have it repeat.

For example, say I have 5 listings in the Northern Heights area. I'd like to display "Nothern Heights" as the first line and the following lines are the listings. When the loop finds the next area, say in the Harbor View location, have it display "Harbor View" and then show the listings for that location and so on for all the locations in my db.

Anyone have any idea how to do this? Any help would be appreciated. This is an ASP page using VBScript.
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: VBScript Recordset Help
30 Jul, 2007 - 09:23 AM
Post #2

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,481



Thanked: 161 times
Dream Kudos: 9050
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
QUOTE(cool263 @ 30 Jul, 2007 - 10:15 AM) *

I'm building a web page that has a list of different realestate locations and pulls this info from a database. The user can filter and view the properties by location. My problem is, is that I would like to display a header above the first location, but not have it repeat.

For example, say I have 5 listings in the Northern Heights area. I'd like to display "Nothern Heights" as the first line and the following lines are the listings. When the loop finds the next area, say in the Harbor View location, have it display "Harbor View" and then show the listings for that location and so on for all the locations in my db.

Anyone have any idea how to do this? Any help would be appreciated. This is an ASP page using VBScript.


Is the location being returned with the query? I assume you are showing miltiple areas in a single page and that's whats causing the problem?

User is online!Profile CardPM
+Quote Post

cool263
RE: VBScript Recordset Help
30 Jul, 2007 - 09:37 AM
Post #3

New D.I.C Head
*

Joined: 17 Jul, 2007
Posts: 19


My Contributions
Yes, to both questions.
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: VBScript Recordset Help
30 Jul, 2007 - 09:40 AM
Post #4

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,481



Thanked: 161 times
Dream Kudos: 9050
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
QUOTE(cool263 @ 30 Jul, 2007 - 10:37 AM) *

Yes, to both questions.


Can you post your code for me, just the loop that displays the listings to the page, and I'll see what I can come up with.

User is online!Profile CardPM
+Quote Post

cool263
RE: VBScript Recordset Help
30 Jul, 2007 - 09:48 AM
Post #5

New D.I.C Head
*

Joined: 17 Jul, 2007
Posts: 19


My Contributions
It's probably not the best code, but here it is:


CODE



<%


    sc = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
    sc = sc & Server.MapPath("properties.xls")
    sc = sc & ";Extended Properties=Excel 8.0"

    Set cn = Server.CreateObject("ADODB.Connection")
    cn.Open sc

    Set rs = Cn.Execute("SELECT * FROM [final$]" & tmpOrderBy)

    With (Response)
    
    counter=0

    Do while rs.EOF = False

    strNewCity = Replace(rs("City")," ", "+")
    strNewAddress = Replace(rs("Address")," ", "+")

            .Write "<table border=0 cellspacing=0 cellpadding=0 class=table>"
            .Write "<tr><td colspan=3>"
            .Write "<div class=name>" & rs("Name") & "</div>"
            .Write "</td></tr>"
            .Write "<tr><td class=pad valign=top>"
            .Write "<table border=0 cellpadding=0 cellspacing=0>"
            .Write image1
            .Write "<tr><td class=text><span class=emph>City:</span> " & rs("Location") & "</td></tr>"
            .Write "<tr><td class=text>" & rs("Address") & "</td></tr>"
            .Write "<tr><td class=text>" & rs("City") & ", " & rs("State") & " " & rs("Zip") & "</td></tr>"
            .Write "<tr><td class=text><span class=emph>Phone:</span> " & rs("Phone") & "</td></tr>"
        .Write "</table>"
            .Write "</td>"
            .Write "<td align=right class=pad valign=top>"
            .Write Email
            .Write "<a href=http://www.mapquest.com/maps/map.adp?city=" & strNewCity & "&state=" & rs("State") & "&address=" & strNewAddress & "&country=us&zoom=8 target=new>Get A Map</a> "
            .Write "<a href=http://www.mapquest.com/maps/map.adp?city=" & strNewCity & "&state=" & rs("State") & "&address=" & strNewAddress & "&country=us&zoom=8 target=new><img src=images/map.gif border=0 alt=Map align=absmiddle vspace=1 /></a><br />"
        .Write Url
            .Write "<a href=#top>Top</a> <a href=#top><img src=images/top.gif border=0  alt=Top align=absmiddle vspace=1></a><br />"
        .Write "</td></tr>"
            .Write "<tr><td class=desc colspan=3>" & Desc & "</td></tr>"
            .Write "</table>"
            .Write "<p>"
            rs.MoveNext
    Loop
    End With
    Set rs = Nothing

    cn.Close
    Set cn = Nothing


%>



User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: VBScript Recordset Help
30 Jul, 2007 - 10:05 AM
Post #6

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,481



Thanked: 161 times
Dream Kudos: 9050
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
I'm assuming rs("Name") is what you're trying to display as a header. Try something like this (it may not work exactly at first but you can tweak it as needed, if you cant let me know and Ill help as much as I can). What you need to do is actually loop within a loop. The first loop is, of course, to display all the properties, the 2nd loop loops through all the properties for the ones for that specific location (rs("Name")), then at the end of that loop it resets the variable for rs("Name") and starts the loop all over again. This should give you a header, all the properties for that header, the next header, and so on.

CODE

<%


    sc = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
    sc = sc & Server.MapPath("properties.xls")
    sc = sc & ";Extended Properties=Excel 8.0"

    Set cn = Server.CreateObject("ADODB.Connection")
    cn.Open sc

    Set rs = Cn.Execute("SELECT * FROM [final$]" & tmpOrderBy)

    With (Response)
    
    counter=0
    Dim sLocation,sLocation2
    Do while rs.EOF = False
    sLocation = rs("Name")
    sLocation2 = sLocation
    strNewCity = Replace(rs("City")," ", "+")
    strNewAddress = Replace(rs("Address")," ", "+")

            .Write "<table border=0 cellspacing=0 cellpadding=0 class=table>"
            .Write "<tr><td colspan=3>"
            .Write "<div class=name>" & sLocation & "</div>"
            .Write "</td></tr>"
            .Write "<tr><td class=pad valign=top>"
            .Write "<table border=0 cellpadding=0 cellspacing=0>"
            .Write image1
    Do While Not rs.EOF and (sLocation = sLocation2)
            .Write "<tr><td class=text><span class=emph>City:</span> " & rs("Location") & "</td></tr>"
            .Write "<tr><td class=text>" & rs("Address") & "</td></tr>"
            .Write "<tr><td class=text>" & rs("City") & ", " & rs("State") & " " & rs("Zip") & "</td></tr>"
            .Write "<tr><td class=text><span class=emph>Phone:</span> " & rs("Phone") & "</td></tr>"
        .Write "</table>"
            .Write "</td>"
            .Write "<td align=right class=pad valign=top>"
            .Write Email
            .Write "<a href=http://www.mapquest.com/maps/map.adp?city=" & strNewCity & "&state=" & rs("State") & "&address=" & strNewAddress & "&country=us&zoom=8 target=new>Get A Map</a> "
            .Write "<a href=http://www.mapquest.com/maps/map.adp?city=" & strNewCity & "&state=" & rs("State") & "&address=" & strNewAddress & "&country=us&zoom=8 target=new><img src=images/map.gif border=0 alt=Map align=absmiddle vspace=1 /></a><br />"
        .Write Url
            .Write "<a href=#top>Top</a> <a href=#top><img src=images/top.gif border=0  alt=Top align=absmiddle vspace=1></a><br />"
        .Write "</td></tr>"
            .Write "<tr><td class=desc colspan=3>" & Desc & "</td></tr>"
            .Write "</table>"
            .Write "<p>"
      rs.MoveNext
      If Not rs.EOF Then
         sLocation2 = rs("Name")
      End If
      Loop
            rs.MoveNext
    Loop
    End With
    Set rs = Nothing

    cn.Close
    Set cn = Nothing

User is online!Profile CardPM
+Quote Post

cool263
RE: VBScript Recordset Help
30 Jul, 2007 - 10:31 AM
Post #7

New D.I.C Head
*

Joined: 17 Jul, 2007
Posts: 19


My Contributions
That worked great! Had to make a minor adjustment, but it works perfectly. Thank you very much for your help, I really appreciate it!!
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: VBScript Recordset Help
30 Jul, 2007 - 10:33 AM
Post #8

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,481



Thanked: 161 times
Dream Kudos: 9050
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
No problem, thats what we're here for smile.gif Have anymore problems feel free to come back.

By the way you dont have to just post programming questions here, the Caffeine Lounge is a great place to hang out.

User is online!Profile CardPM
+Quote Post

Amadeus
RE: VBScript Recordset Help
30 Jul, 2007 - 10:35 AM
Post #9

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,349



Thanked: 51 times
Dream Kudos: 25
My Contributions
Good job, Psycho! And I thought I was the only one left here who worked with classic vbscript! wink2.gif
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: VBScript Recordset Help
30 Jul, 2007 - 10:39 AM
Post #10

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,481



Thanked: 161 times
Dream Kudos: 9050
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
QUOTE(Amadeus @ 30 Jul, 2007 - 11:35 AM) *

Good job, Psycho! And I thought I was the only one left here who worked with classic vbscript! wink2.gif

I work with it if I have to, otherwise I stick with ASP.Net. Also, I've used classic ASP for so long it's like riding a bicycle, once you learn you never forget. I bet I have every ASP website I've ever created on one of my hard drives (thats 10+ years of coding by the way)

User is online!Profile CardPM
+Quote Post

Amadeus
RE: VBScript Recordset Help
30 Jul, 2007 - 10:43 AM
Post #11

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,349



Thanked: 51 times
Dream Kudos: 25
My Contributions
I hear you...VBScript was the language I used when I broke into web programming...seems like a long time ago now!
User is offlineProfile CardPM
+Quote Post

cool263
RE: VBScript Recordset Help
30 Jul, 2007 - 10:45 AM
Post #12

New D.I.C Head
*

Joined: 17 Jul, 2007
Posts: 19


My Contributions
One of these years, I'll graduate to .NET, but right now, I'm still learning to program. smile.gif
User is offlineProfile CardPM
+Quote Post

2 Pages V  1 2 >
Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 06:43PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month