Solved

Horizontal Separator

Posted on 2002-06-02
22
428 Views
Last Modified: 2012-08-14
Hello,

I have an ASP page that will generate a table for reporting purposes.  I'm looping through the recordset and building the rows.  What I need to do is separate the records with a horizontal rule <h1> by dates. For example, the table will have 20 rows of records.  The first 10 records will be separated from the next 10 records because it's dates are in 2001 instead of 2002.  How can I add an <h1> tag to separate these records. Also, In my sql statement, I'm ordering the records by dates

Thanks
0
Comment
Question by:tinman1412
  • 5
  • 4
  • 4
  • +5
22 Comments
 
LVL 4

Expert Comment

by:RichW
ID: 7050183
If you know the number of records just set an integer variable and test for that number.

<%
Dim x as Integer
x = 1

Do While <=== your normal Do Loop
  If x = 10 Then
%>
<hr>
<%
  End If
  x = x + 1
  rs.MoveNext
  If x = 10 Then
     x = 1
  End If
Loop
%>
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 7050523
RichW, this is ASP, not VB nor ASP.Net.

No such thing as Dim x As Integer!
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 7050528
<%
Dim lngCount
lngCount = 0

'connect to db
'execute sql and get recordset

While Not oRS.EOF
 lngCount = lngCount + 1
 If lngCount Mod 10 = 0 Then
  Response.Write "<hr>"
 End If
 'do your processing with the recordset

 oRS.MoveNext
Wend
%>
0
 

Expert Comment

by:R_A_I
ID: 7050722
<%
Dim curyear
Dim tmpyear

'-- connect to db
'-- execute sql; assign recordset var to ors

tmpyear = Year(CDate(ors.Fields("dbdate"))) '-- dbdate is your valid date field

curyear = tmpyear

Do While not ors.eof

if tmpyear<>curyear then
 response.write "<hr>"
 curyear = tmpyear
end if

 tmpyear = Year(CDate(ors.Fields("dbdate")))
 '-- your stuff here...
 ors.movenext

Loop
0
 
LVL 4

Expert Comment

by:RichW
ID: 7050825
b1xml2 ,

I know there's no setting of data type in ASP.  For crying out loud everything is a Variant data type, but in an example you try to get your point across by showing the intended data type.  Besides, the ASP engine will convert to Integer before a Long anyway.  

Just out of curiosity, why are you using a Mod?  You're using extra overheard to perform a Mod calc, rather than just checking the variable for a number.

RichW
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 7050827
RichW, there is no conversion of integer to long in the ASP code, just a convention of naming the variable.

>>
Besides, the
ASP engine will convert to Integer before a Long anyway.  
<<
what are you talking about? I am not using CLng(). Overhead if any is miniscule when using Mod

>>
For crying out loud everything is a Variant data type,
<<
Everything is variant. Using a mod provides cleaner readable code.
0
 
LVL 4

Expert Comment

by:RichW
ID: 7050854
I'm afraid you're wrong, my friend.  The ASP engine decides which data type is best used and does do a conversion when a calc is requested.  

My point with Int vs Lng was just that, a point.  I was pointing out that since the number is set first as 1, the ASP engine would use the Variant variable as an Integer before a Long data type in the conversion.

I'm not saying you can use these data types in your scripting.  I am saying that the Variant type is converted by the ASP engine in the background.  This is a fact.

Using Mod is effective, but I believe it uses a tad bit more overhead than say, testing for the number alone.

I've just never seen Mod used that way, so I was curious.

Cheers,
RichW

0
 
LVL 19

Expert Comment

by:webwoman
ID: 7050934
All of this assumes they're in date order -- are they? If not, you'll need to order them that way.

I usually set a variable at the beginning, load it with the first value in the recordset, and when the current records doesn't match I write the line/headings/etc.. Then I reset the variable with the new value.

Nothing fancy, but it works. ;-)
0
 
LVL 4

Expert Comment

by:Zvika
ID: 7051050
tinman, RAI answer is the best for my opinion, it just has a little bug that will put the <hr> one line after the first 2002 row, that's because the line:
tmpyear = Year(CDate(ors.Fields("dbdate")))
is done after the:
if tmpyear<>curyear then
So, here is the same code, just withthe fix (and a bit of my style of code, choose the one you are more familiar with):
<%
'assuming you have declared and set your RecordSet
'to a variable named rs

Dim currentYear
Dim rsYear

currentYear = Year(CDate(rs("yourDateFieldName")))

Do Until rs.EOF
     rsYear = Year(CDate(rs("yourDateFieldName")))
     If currentYear <> rsYear Then
          response.write "<hr>"
          'or any other code you'd like to print between the year chunks
          currentYear = rsYear
     End If
     'here put all the regular code you do in each row
     rs.MoveNext
Loop  
%>

If you need more help, add a comment
0
 
LVL 4

Expert Comment

by:Zvika
ID: 7051065
RichW, all your explanation about the long or integer are fine, but if you will write a code like
dim i as integer
the asp engine will raise an error on your line of code, because it can't parse the "as" - it's an error for it, so b1xml2 is totaly right on that point.
about the mod - the overhead is really miniscule and the readability of the code is much clearer - and shorter code, so again, I go with b1xml2

webwomen
>> Also, In my sql statement, I'm ordering the records by dates
this is not like you not to read the question till the end ;)

tinman1412
Note that both RichW's & b1xml2's solution will work if each chunks contains the same number of rows, and that you know this number.

0
 
LVL 18

Expert Comment

by:bruno
ID: 7051071
a few notes:

<h1> is much different than <hr>, i assume this was just an oversite as you were writing the question.

you'll need to modify your code to actually put the <hr> into a TD cell that will span the width of the table, or you will have to close out the table first, then write out the <hr> then open the next table again.  you can not just put an <hr> between </tr> <tr> as is likely to happen if you are looping thru the rs while building the table.


BRUNO
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 4

Expert Comment

by:RichW
ID: 7051130
Zvika,

I agree with you 100%.  I should've written it as:
Dim x ' as Integer <== this will be an Integer subtype:
to explain the incremental functionality.

I didn't want to get into a pissing contest with anyone.

I apologize.  

I also like to use as little overhead as possible, and I've never seen Mod used that way.  I've used Mod to find out the leftover have of a value.  Pretty neat the way he used the Mod, so I was actually impressed, but didn't know why.  lol

Cheers,
RichW
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 7051143
LOL, RichW. Modulus can make life so much easier in XSLT and I merely ported my experience there to here in ASP =))
0
 
LVL 4

Expert Comment

by:RichW
ID: 7051153
Well, that's why I love this field.  We learn something new every day.  :)

RichW
0
 

Author Comment

by:tinman1412
ID: 7051228
All,

I think I left out some information. I'm actually using the GetRows method of the recordset, but I don't think this should matter.  Also, I do not know the number of records, so I can't set a variable and test for it.  What I was aiming at is that all the records that are a month away from the current date will be separated by a <hr>. Please let me know. I think RAI has the right idea along with brunobear's comments about closing and creating another <table>.  Please respond to my new information

Thanks
0
 

Expert Comment

by:raja_velpuru
ID: 7051888
tinman1412, can u give an example of how typically records would be and the expected result.
0
 

Author Comment

by:tinman1412
ID: 7051936
Alright, Lets say I have a recordset with 3 fields, "name", "date", "Days Ago".  The records are ordered by date.  There's not a defined number of records, because records are added everyday.  In my ASP page, I have a table and building my rows dynamically with my recordset.  I'm trying to check the date, For all the records that are a month away from the current date, I will insert a <hr> to separate the records. An example of my output is below


Name                     Date                    Days Ago
Bob                      6-3-2002                    0
John                     5-25-2002                   8  
Mike                     5-10-2002                   ""
Dennis                   5-3-2002                    ""
------------------------------------ <hr>
Mary                     4-25-2002
Michelle                 3-12-2002
Kay                      2-10-2002


How can I do this on my ASP page?

Thanks

0
 

Accepted Solution

by:
raja_velpuru earned 50 total points
ID: 7051989
As I understand from ur explanation, in the output u will have two parts, the bottom part being with dates which are a month or more away from the current date.

1. First of all, your query should return records order by date in descending order.

2. Before displaying the record ur program logic would like look something like this:

do until rs.eof
   if ((current_date - rs.date) >= 1 month) then
      if HRFlag <> "Y" then
         display <HR>
         HRFlag = "Y"
      end if
   end if
   display the date record
loop
0
 
LVL 4

Expert Comment

by:Zvika
ID: 7053600
tinman
I hope the following code will be good enough for you:
(Assuming your Recordset is defined and is named rs, and its field order is name, date, days)

dim anArray    'your array for the GetRows
dim i          'index
dim theDate    'parameter ro hold the delimiting date
dim HRprinted  'boolean fo weather or not the HR was printed

HRprinted = false
theDate = dateadd("m",-1, date()) 'calculating a month before today
anArray = rs.GetRows()
response.write("<table>")
for i = 0 to UBound(anArray,2) 'looping all the array length
     if not HRprinted then
          if cDate(anArray(1,i)) < theDate then
'if the HR wasn't printed yet, and the date in the current record is less then the delimiting date, then change the flag, close the table, print the HR and open another table
               HRprinted = true
               Response.Write("</table><hr><table>")
          end if
     end if              
'here put all the code that prints each line, something like:
        response.write("<tr><td>" & anArray (0,i) & "</td>")
        response.write("<td>" & anArray (1,i) & "</td>")
        response.write("<td>" & anArray (2,i) & "</td></tr>")
next
response.write("</table>")

I hope that is what you need
If you need any more help, add a comment.
Good Luck
Zvika
0
 

Author Comment

by:tinman1412
ID: 7053781
Thanks for all the help.  Is there a way to split the points between 2 people
0
 
LVL 4

Expert Comment

by:Zvika
ID: 7053796
post a question in the community support section.
they will help you.
(Or you can give the points to one, then open another fictive question named "points for John Doe") - depends if you want to split the 50 or give 50 to each
0
 
LVL 18

Expert Comment

by:bruno
ID: 7053806
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now