473,387 Members | 1,516 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Display complex table from Access DB

This has been driving me up the wall for a couple of weeks. I set out to convert my comic collection check list (geek that I am!) from a static HTML table to a dynamic ASP generated one.

The static one looks like this:
www.thestoryworks.com/publishing/comics/collecting/wants63.htm
which is the look I'm trying to replicate in a dynamic version.

My dynamic one currently looks like this:
www.tmcreative.co.uk/db/buildtable01_orig.asp
As you can see, it is starting a new line for each issue, rather than rendering a year of Spider-Man issues on a single line.

The code looks like this:

Expand|Select|Wrap|Line Numbers
  1. <%
  2. Option Explicit
  3. Dim strConnect
  4. %>
  5. <!-- #include file="admin/connect_local.asp" -->
  6. <!-- METADATA TYPE="typelib" 
  7.               FILE="C:\Program Files\Common Files\System\ado\msado15.dll" -->
  8.  
  9. <HTML>
  10. <HEAD>
  11. <title>TheStoryWorks.com :: Comics :: Collecting :: Marvel 1963</title>
  12. <link href="style.css" rel="stylesheet" type="text/css">
  13. </pre></HEAD>
  14. <BODY>
  15.  
  16. <%
  17.  
  18.   Dim objCommand, objRS, varCounter, varMonthCount, varMonthCount10, varLoop, num
  19.   Set objCommand = Server.CreateObject("ADODB.Command")
  20.  
  21.   objCommand.ActiveConnection = strConnect
  22.  
  23.   objCommand.CommandText = "SELECT Title.titleName, Item.issue, Item.month, Item.year, Item.have " & _
  24.        "FROM Title INNER JOIN Item ON Title.idTitle = Item.idTitle " & _
  25.        "WHERE (Item.year LIKE '63') ORDER BY titleName,month;"
  26.  
  27.   objCommand.CommandType = adCmdText
  28.  
  29.   Set objRS = objCommand.Execute
  30.   Set objCommand = Nothing
  31.   varMonthCount = 1
  32.   varMonthCount10 = 10
  33.  
  34.     Response.Write "<table width='100%' border='0' cellspacing='0' cellpadding='2'>"
  35.     Response.Write "<tr bgcolor='cccccc'><td class='bold'>Date Published</td>"
  36.   For varCounter = 1 to 9    
  37.     Response.Write "<td class='bold'>0" & varMonthCount & "/" & objRS("year") & "</td>"
  38.     varMonthCount = varMonthCount + 1
  39.   Next
  40.   For varCounter = 10 to 12
  41.     Response.Write "<td class='bold'>" & varMonthCount10 & "/" & objRS("year") & "</td>"
  42.     varMonthCount10 = varMonthCount10 + 1
  43.   Next
  44.     Response.Write "<tr>"
  45.   For varCounter = 1 to 13
  46.     Response.Write "<td>&nbsp;</td>"
  47.   Next
  48.     Response.Write "</tr>"
  49.     Response.Write "<tr>"
  50.  
  51. ' RENDER BODY OF TABLE
  52.  
  53. num = 0
  54.  
  55. While Not objRS.EOF
  56.   Response.Write "<tr><td class='bold'"
  57.  
  58. ' WE WANT ALTERNATING ROWS, GREY AND WHITE, SO WE USE THE  
  59. ' NUM VARIABLE TO TELL US WHAT COLOUR TO MAKE EACH TABLE ROW...
  60.  
  61.   if num mod 2 = 0 then Response.Write " bgcolor=#ffffff" Else Response.Write " bgcolor=#cccccc"
  62.   if num <> 0 then
  63.   end if
  64.  
  65.   Response.Write ">" & objRS("titleName") & "</td>"
  66.  
  67. ' BEGIN TO RENDER THE ISSUE NUMBERS
  68.  
  69.     varloop = 1
  70.     For varloop = 1 to 12
  71.     Response.Write "<td align='center'"
  72.  
  73. ' CHOOSE ROW COLOUR FOR ISSUE MUMBERS
  74.  
  75.       if num mod 2 = 0 then Response.Write " bgcolor=#ffffff" Else Response.Write " bgcolor=#cccccc"
  76.       if num <> 0 then
  77.       end if
  78.  
  79. ' IF I HAVE THE ISSUE, RENDER IT IN BOLD
  80.  
  81.     If objRS("have") = True Then Response.Write " class='bold'>" Else Response.Write ">" End If
  82.  
  83. ' RENDER THE ISSUE NUMBER
  84.  
  85.   If objRS("month") = varLoop then Response.Write objRS("issue") else Response.Write "-" end if
  86.   Response.Write "</td>"
  87.  
  88. '    LOOP TO THE NEXT ISSUE
  89.     'objRS.MoveNext
  90.     Next
  91.  
  92. ' MOVE TO THE NEXT TITLE AND LOOP AGAIN
  93.  
  94. Response.Write "</tr>"
  95. objRS.MoveNext
  96. num = num + 1
  97.  
  98. wEnd
  99.  
  100. objRS.Close
  101. Set objRS = Nothing
  102. %>
  103. </table>
  104. </BODY>
  105. </HTML>
So ... right after the comment "RENDER THE ISSUE NUMBER" I know I have to moveNext somehow, but when I uncomment that line, I get an error.

So I tried this:
Expand|Select|Wrap|Line Numbers
  1. ' RENDER THE ISSUE NUMBER
  2.  
  3.   If objRS("month") = varLoop _
  4.   then Response.Write objRS("issue")
  5.   objRS.MoveNext
  6.   else Response.Write "-"
  7.   end if
  8.   Response.Write "</td>"
So that where an issue wasn't published that month, the code would render a "-". Should work, right? Uh-uh - another error. Says, "expected Next after the objRS.MoveNext".

I can't figure what I'm doing wrong ... thought it's probably screamingly obvious to the proper ASP coders on this forum.

Anyone have any ideas?

Peck2000
London
Jun 4 '07 #1
5 1459
jhardman
3,406 Expert 2GB
why is line 89 commented out? as it stands now you make a new </tr><tr> for each record, and it seems like you should just make a new </td><td>

Jared
Jun 4 '07 #2
jhardman
3,406 Expert 2GB
Sorry, I didn't read it too close. You did answer that.

I've handled a similar question. Let me see if I can work up a solution.

Jared
Jun 5 '07 #3
jhardman
3,406 Expert 2GB
look at line 85. This should read:
Expand|Select|Wrap|Line Numbers
  1. If objRS("month") = varLoop then
  2.     Response.Write objRS("issue") 
  3.     objRS.moveNext
  4. else
  5.     Response.Write "-" 
  6. end if
If you find a match (the month of the table cell indicated matches the month of the issue) you should advance then. You don't need to wait til the end of the table row.

I would also keep track of the titleName in a separate variable, so if that ever changes I know I need to change rows:
Expand|Select|Wrap|Line Numbers
  1. tName = objRS("titleName")
  2. 'etc etc
  3. objRS.moveNext
  4. if objRS("titleName") <> tName then
  5.    response.write "</tr><tr>"
  6.    'strat the next row
  7. end if
Jared
Jun 5 '07 #4
Hey, Jared ...

This is a great help ... thanks!

Implementing your changes, I now have a page that displays like this:

www.tmcreative.co.uk/db/buildtable02_orig_fix.asp

which is close ... real close :-)

However, It's still not displaying right. The problem is a complex one and took me a little while to figure out. The problem arises when you have a sequence of issues like The Avengers for 1963. Issue 1 was September, issue 2 was November and issue 3 was Jan 1964.

On the twelfth trip round the loop, the code doesn't find an Avengers issue for December in the database. So it moves to the row, changing the Title (Fantastic Four), and compares the month of the issue (10, Jan) with the varloop variable, doesn't get a match and moves to the next issue (11), doesn't get a match, prints a "-".

Then it loops round again, gets a matching month (Feb) for FF11, and prints the issue number in the table ... missing out issue 10!

Soooo ... I know what's going wrong, but I can't figure out how to programme round the glitch.

The easy way would be to place a dummy issue of Avengers in the datbase dated Dec with an issue number of "-", but that's a cheat and doesn't address the real problem.

I'm sure there's a clue in the bit of code you posted last time:
Expand|Select|Wrap|Line Numbers
  1.  tName = objRS("titleName")
  2.  'etc etc
  3.  objRS.moveNext
  4.  if objRS("titleName") <> tName then
  5.  response.write "</tr><tr>"
  6.  'start the next row
  7.  end if
But implementing this didn't solve the problem. By the time weve tested to see if the Title has changed we're already in that database row, and going round the loop again causes us to moveNext before we're ready.

So, while I'm trying to think this through, I could use any help or advice anyone can offer ...

So close ... so close :-)

peck2000
Jun 6 '07 #5
jhardman
3,406 Expert 2GB
I almost suggested starting over, but I don't think you have to yet. I might make you retract what I originally told you to do, though.

Think of the logic like this. your list is always going to be in the same order but there are some holes in the list. As you loop through the list you will see occasionally that there is a month that doesn't have an issue for that title. If you want to print something (albeit a "-") then you will need to loop through every month for every title and check that you are on the right month and the right title at every step.

So say your first record is for Avengers and it is in June. You print "Avengers" because you know that that is your title, and save this name as some variable like "currentTitle". Then you go to the January spot. Is the month january AND the title=currentTitle? no, so print "-" and go to the next month. Is the month Feb AND the title=currentTitle? no, so go to the next month ...Is the month June AND the the title=currentTitle? yes, so you have to do three things: Print the issue number and indicate whether you have it. Second move to the next record in youjr recordset. Third, continue on to the next month. Finally you will get to December. At this point you will either have a December issue for the Avengers and that is your current record, or your current record is the next title. After you print the "-" or issue number and do all the things you needed to do to advance the recordset, you need to draw the next line. Write the next title. Change the variable "currentTitle" to the title of the current record, and check January. Is the month of the current record January and the title = currentTitle? etc.

so i guess I would organize it in a loop like this:
Expand|Select|Wrap|Line Numbers
  1. dim mon, currentTitle
  2. mon = 1
  3.  
  4. do until objRS.eof
  5.    if mon = 1 then  
  6.       currentTitle = objRS("title") 
  7.       response.write "<tr><td>" & currentTitle & "</td>" & vbNewLine
  8.    end if 
  9.  
  10.    if objRS("month") = mon AND objRS("title") = currentTitle then
  11.       response.write "<td>" & objRS("issueNum") & "</td>" & vbNewLine
  12.       objRS.moveNext
  13.    else
  14.       response.write "<td>-</td>" & vbNewLine
  15.    end if
  16.  
  17.    mon = mon + 1
  18.    if mon = 13 THEN
  19.       mon = 1
  20.       response.write "</tr>"
  21.    end if
  22. loop
  23. response.write "</table>"
  24.  
Now I know some of this isn't compatible with how you set up your script and db etc. but looking at what you have done so far I'm pretty confident that you can adapt it to fit what you need. Let me know if this helps.

Jared
Jun 14 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Mahesh Hardikar | last post by:
Hi , Oracle 8.1.7.0.0 on HP-UX 11.0 I am a newbie as far as PL-SQL is concerned . I have Sybase/MSSQL T-SQL background. We have a report which uses a select statement . This select...
3
by: Marcus | last post by:
Hi I have a very complex sql query and a explain plan. I found there is a full table scan in ID=9 9 8 TABLE ACCESS (FULL) OF 'F_LOTTXNHIST' (Cost=84573 Card=185892...
116
by: Mike MacSween | last post by:
S**t for brains strikes again! Why did I do that? When I met the clients and at some point they vaguely asked whether eventually would it be possible to have some people who could read the data...
3
by: DataBard007 | last post by:
My Access 97 database has a form that contains text boxes that display people's names, addresses, phone numbers, etc. The record source is a single table. I created a NextRecord and Previous...
8
by: Steve Jorgensen | last post by:
Mailing List management is a good example of a case where my conundrum arises. Say there is a m-m relationship between parties and groups - anyone can be a member of any combintation of groups. ...
3
by: Ben R. | last post by:
Since the original thread is marked as answered, I thought I'd post here to ensure visibility. Hi John and Steven, I'm going the dataset route as access doesn't seem to be too keen on that...
6
by: Jon Bilbao | last post by:
I´m trying a select clause in two steps because it´s too complex. First: SELECT Reference, Results.idEnsayo, Results.Num_taladro, min(Results.dTime) + 500 AS tIni, max(Results.dTime) - 500 AS...
3
by: phil67b | last post by:
Hello everybody, I have a page rech.php where I'm doing a multi-criteria research Ex. choose your car model, choose your country. After validation of my form, on the same page, the lines will be...
16
by: blaze77 | last post by:
Hi, I'm somewhat of a power user in excel and a newbie to Access though the possibilities are exciting me :-) I am trying to create a tool in Access to replace an existing tool in Excel. My...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.