Display of Records in Table

Results 1 to 6 of 6

Thread: Display of Records in Table

  1. #1
    Mads Nordskov Guest

    Default Display of Records in Table

    I am trying to display all the records of a table on a page. I want them to spread out in 3 columns of an html-table... this sounds simple, but I can&#039t get it done... please help<BR><BR>Mads

  2. #2
    Bijal Guest

    Default RE: Display of Records in Table

    here&#039s a piece of code to display all the records from a database table onto an HTML page:<BR><BR>&#060;html><BR>&#060;%<BR>Dim db, dbRs<BR>Set db = Server.CreateObject("ADODB.Connection")<BR>db.Open "TestDatabase"<BR> <BR>Set dbRs = db.Execute("SELECT field1, field2, field3 FROM table_Name")<BR>If dbRs.eof Then<BR> response.write "No records matched<BR>"<BR> dbRs.close<BR> set dbRs = Nothing<BR> response.end<BR>End If<BR>&#037;&#062;<BR>&#060;head><BR>&#060;title>D isplay Records from Database Table&#060;/title><BR>&#060;/head><BR><BR>&#060;body><BR>&#060;TABLE cellspacing=0 cellpadding=3 border=0><BR>&#060;TR bgcolor="#000000"><BR> &#060;TD align=center width="33%">&#060;FONT color="#ffffff" face="arial, helvetica" size=2>&#060;B>Field1&#060;/TD><BR> &#060;TD align=center width="33%">&#060;FONT color="#ffffff" face="arial, helvetica" size=2>&#060;B>Field2&#060;/TD><BR> &#060;TD align=center width="33%">&#060;FONT color="#ffffff" face="arial, helvetica" size=2>&#060;B>Field3&#060;/TD><BR>&#060;/TR><BR><BR>&#060;% <BR>DO UNTIL dbRs.EOF &#037;&#062;<BR>&#060;TR bgcolor="#cccccc"><BR> &#060;TD valign=top align=center><BR> &#060;INPUT name="data1" value="&#060;%=dbRs("Field1")&#037;&#062;">&#060;/TD><BR> &#060;TD valign=top align=center><BR> &#060;INPUT name="data2" value="&#060;%=dbRs("Field2")&#037;&#062;">&#060;/TD><BR> &#060;TD valign=top align=center><BR> &#060;INPUT name="data3" value="&#060;%=dbRs("ApplicationDate")&#037;&#062; ">&#060;/TD><BR>&#060;/TR><BR><BR>&#060;% <BR> dbRs.movenext<BR>LOOP &#037;&#062;<BR><BR>&#060;/TABLE><BR><BR><BR>&#060;%<BR> dbRs.Close<BR> Set dbRs = Nothing<BR><BR> db.Close<BR> Set db = Nothing<BR>&#037;&#062;<BR> <BR>&#060;/body><BR>&#060;/html><BR><BR>Hope this helps.<BR><BR>Bijal.<BR>

  3. #3
    Mads Nordskov Guest

    Default RE: Display of Records in Table

    Hi Bijal.<BR><BR>Thanks for your help. I figured the same out for myself. But the problem is that your script puts a different field in each column. What I need is the different records (containing fields)to spread out over 3 columns.<BR><BR>Mads.

  4. #4
    Join Date
    Dec 1969
    Posts
    1,315

    Default RE: Display of Records in Table

    Here&#039s only a thought:<BR>You need to get the number of records first. <BR>Use RecordCount to get it. Divide it by 3. This gives you how many times you need to loop.<BR>Let&#039s say, RecordCount gives you 15 records. That means you need<BR>to loop 5 times.<BR>What you want is to "print"<BR>record 1, 6, and 11 in one line<BR>record 2, 7, and 12 in one line<BR>record 3, 8, and 13 in one line<BR>record 4, 9, and 14 in one line<BR>record 5, 10,and 15 in one line<BR><BR>Create 3 identical recordsets, say rs1, rs2, rs3.<BR>Move rs1 to the 1st record<BR>Move rs2 to the 6th record<BR>Move rs3 to the 11th record<BR><BR>Now, loop 5 times simultaneously while "printing" rs1, rs2, rs3.<BR>Use MoveNext to go to next record.<BR>(It&#039s probably better to create only 1 recordset, but you need to<BR>move it to the 1st record, print it, 6th record, print it, 11th<BR>record, print it etc).<BR>The result is a 3 column list of records.<BR>1st column contains record 1 to 5<BR>2nd column contains record 6 to 10<BR>3rd column contains record 11 to 15.<BR><BR>Anyway, it&#039s only my thought. I&#039ll let you implement it.<BR><BR>Cheers,<BR><BR>John Weeflaar


  5. #5
    Join Date
    Dec 1969
    Posts
    1,315

    Default RE: Display of Records in Table

    I don&#039t know if it works when you create 3 identical recordsets,<BR>because I&#039ve never tried this.<BR>One thing I don&#039t know is when rs1 points to the first record,<BR>will that mean rs2 and rs3 also point to the first record. I guess so. Similarly, when rs2 points to the 6th record, will that<BR>mean rs1 and rs3 point to the 6th record. If that&#039s the case then<BR>you can&#039t create 3 recordsets, one points to the 1st record, the other points to the 6th record, the other points to the 11th record, and the idea I showed wouldn&#039t work. What you will need<BR>then is to create a recordset that points to the 1st record,<BR>"print", move it to point to the 6th record, "print", move it to<BR>the 11th record, "print", move it point to the 2nd record, etc.<BR>So, we have 1 6 11, 2 7 12, 3 8 13, 4 9 14, 5 10 15.<BR>So, 5 times looping, and moving the record pointer 3 times to "print" in each loop.<BR>You can see that it&#039s not that easy. You need to also consider<BR>other numbers, and start using variables etc.<BR>Perhaps there is a better idea.<BR><BR>John Weeflaar<BR>

  6. #6
    Join Date
    Dec 1969
    Posts
    1,315

    Default It's possible, simpler and fast, but ...

    Mads,<BR><BR>Yes, it is possible, simpler, and fast, but it will be easier if you add a counter field in your table. Are you familiar with self join?<BR><BR>John Weeflaar

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •