Formatting dynamic tables

D

Debbie Davis

Greetings,

I have a table called locations which holds 9 store locations. I am at
my wit's end trying to format these like this:

centered

City Name(named once)
store store store store

next, etc.

Here's my dilemna: Some cities only have 1 location, some have 4, some
have 3. I don't know how to dynamically get them all centered under the
city names (which I only need listed once) because of the different
number of stores for each city. Thanks in advance.

dd
 
T

Tom B

Dim sSQL
sSQL="SELECT CityName, StoreName from Locations ORDER BY CityName"
Set RS=CN.Execute(sSQL)
Dim sCurrentCity
if not RS.EOF Then
Do While not RS.EOF
if sCurrentCity<>RS.Fields("CityName") then
'it's the next city.
sCurrentCity=RS.Fields("CityName")
Response.Write "<br>" & sCurrentCity & "<br>"
end if
'Display the store name (and other information)
Response.Write RS.Fields("StoreName") & " "

RS.MoveNext
Loop
end if
Set RS=nothing
CN.Close
Set CN=nothing

The Recordset returned will look like this.......
Las Vegas Store1
Las Vegas Store 2
Paris Store3
Paris Store4
Paris Store5

All you have to do is loop through the recordset, each time you get a new
city name, then write it out.

All leave the formatting up to you.
 
D

Debbie Davis

Thanks Tom. It's the formatting I'm having the problem with. I only
need the city name once then the stores listed across under the city
name, centered.


San Antonio
Store 1 Store 2 Store 3 Store 4

Austin
Store 1 Store 2 Store 3

Etc.

Where I'm having the problem is centering each row when some cities have
4 stores, some have 2 some have 1, etc.

Thanks anyway for your help!!
 
T

Tom B

What HAVE you got?
The easiest is to just use....

<center>San Antonio</center>
<br>
<center>Store 1 Store 2 Store 3 Store 4</center>
 
D

Debbie Davis

Thanks again, Tom. I really didn't want to post all of this but here
goes.

set loc=objConn.execute("select * from locations")
Response.Write "<table align=center width='100%'>"
While NOT loc.EOF
strCity = loc("city")
If strCity <> strOldCity Then
Response.Write "<tr><td valign=top colspan=4 align=center><font
size=4><strong>" & strCity & "</strong></font><tr>"
End If
Response.write "<td align=center><strong>" & loc("geographic") &
"</strong>"
Response.write "<br><strong>" & loc("telephone") & "</strong>"
Response.Write "<br>" & loc("address") & "<br>" & loc("city") & ", " &
loc("state") & " " & loc("zip")
strOldCity = strCity
loc.MoveNext
Wend
Response.Write "</table>"

This works except for the formatting problem. 4 is the highest number
of stores per city, and of course that centers properly, but the next
city has 1, the next has 3 and they are aligned to the left. It's no
big deal. I'll just align everything left, but it would look better
centered.

Many thanks again, though for all of your help. Your method works
great, also.
 
A

Alex G

This is because the rows with just 1 location aren't column spanning
across the 4 cells, try putting each city in it's own table, try this

set loc=objConn.execute("select * from locations")
bolFirstCity = 1
While NOT loc.EOF
strCity = loc("city")
If strCity <> strOldCity Then
If not bolFirstCity = 1 then
Response.Write "</table><br>"
Else
bolFirstCity = 0
End If
Response.Write "<table align=center width='100%'>"
Response.Write "<tr><td valign=top colspan=4 align=center><font
size=4><strong>" & strCity & "</strong></font></td></tr><tr>"
End If
Response.write "<td align=center><strong>" & loc("geographic") &
"</strong>"
Response.write "<br><strong>" & loc("telephone") & "</strong>"
Response.Write "<br>" & loc("address") & "<br>" & loc("city") & ", " &
loc("state") & " " & loc("zip")
strOldCity = strCity
loc.MoveNext
Wend
Response.Write "</table>"
 
R

Roland Hall

Hi Debbie...

Something similar to this?
http://kiddanger.com/lab/storesandcities.asp

--
Roland

This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose.
-Technet Knowledge Base-
http://support.microsoft.com/default.aspx?scid=fh;EN-US;kbhowto&sd=TECH&ln=EN-US&FR=0
-Technet Script Center-
http://www.microsoft.com/technet/treeview/default.asp?url=/technet/scriptcenter/default.asp
-MSDN Library-
http://msdn.microsoft.com/library/default.asp
 
D

Debbie Davis

WOW, thanks Alex. That makes perfect and also worked perfectly. Many
thanks again!!
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top