Home All Groups Group Topic Archive Search About

Generate a table with ASP

Author
23 Mar 2005 4:33 PM
Øyvind Isaksen
Hi!

I need to create a table with 4 cols and X rows based on the number records
in my database. I dont know how this can be done, mabye with an array?

If I got for example 6 records in my database, a table with 4 cols and 2
rows should be generated, the last row will only have 2 cols with
information...

Like this:

<table>
<tr>
   <td>Record1</td>
   <td>Record2</td>
   <td>Record3</td>
   <td>Record4</td>
</tr>
<tr>
   <td>Record5</td>
   <td>Record6</td>
   <td></td>
  <td></td>
</tr>
</table>

-----------------------------------

This is what I have made so far:
<table>
<%
set rsArt= server.CreateObject("adodb.recordset")
   rsArt.Open SQL,conn

      do until rsArt.EOF

      rsArt.MoveNext
      loop

   rsArt.Close
set rsArt = nothing
%>
</table>

-----------------------------------


Can someone please help me with this one???

Regards,
Øyvind Isaksen

Author
23 Mar 2005 4:52 PM
Ray Costanzo [MVP]
So, your recordset just has one column being returned?  How about something
like:


<table>
<%
Const COLUMNS = 4
Dim i : i = 0

Do While Not rs.EOF
    If i Mod COLUMNS = 0 Then Response.Write " <tr>" & vbCrLf
    Response.Write "  <td>" & rs(0) & "</td>" & vbCrLf
    If i Mod COLUMNS = COLUMNS - 1 Then Response.Write " </tr>" & vbCrLf
    i = i + 1
rs.MoveNext
Loop



''fill in some empty tds with &nbsp; if needed
If i Mod COLUMNS  <> 0 Then
    For j = 1 To COLUMNS - (i Mod COLUMNS)
        Response.Write "  <td>&nbsp;</td>" & vbCrLf
    Next
    Response.Write " </tr>"
End If
%>
</table>

Ray at work

Show quoteHide quote
"Øyvind Isaksen" <oyv***@webressurs.no> wrote in message
news:%23N%238eY8LFHA.3228@TK2MSFTNGP12.phx.gbl...
> Hi!
>
> I need to create a table with 4 cols and X rows based on the number
records
> in my database. I dont know how this can be done, mabye with an array?
>
> If I got for example 6 records in my database, a table with 4 cols and 2
> rows should be generated, the last row will only have 2 cols with
> information...
>
> Like this:
>
> <table>
> <tr>
>    <td>Record1</td>
>    <td>Record2</td>
>    <td>Record3</td>
>    <td>Record4</td>
> </tr>
> <tr>
>    <td>Record5</td>
>    <td>Record6</td>
>    <td></td>
>   <td></td>
> </tr>
> </table>
>
> -----------------------------------
>
> This is what I have made so far:
> <table>
> <%
> set rsArt= server.CreateObject("adodb.recordset")
>    rsArt.Open SQL,conn
>
>       do until rsArt.EOF
>
>       rsArt.MoveNext
>       loop
>
>    rsArt.Close
> set rsArt = nothing
> %>
> </table>
>
> -----------------------------------
>
>
> Can someone please help me with this one???
>
> Regards,
> Øyvind Isaksen
>
>
Are all your drivers up to date? click for free checkup

Author
23 Mar 2005 4:55 PM
Curt_C [MVP]
X=1
....loop start.....
X=X+1
if x=4 then
...</tr><tr>...
....X=1
End if
....loop end...

You get the idea...

--
Curt Christianson
Site & Scripts: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com


Show quoteHide quote
"Øyvind Isaksen" <oyv***@webressurs.no> wrote in message
news:%23N%238eY8LFHA.3228@TK2MSFTNGP12.phx.gbl...
> Hi!
>
> I need to create a table with 4 cols and X rows based on the number
> records in my database. I dont know how this can be done, mabye with an
> array?
>
> If I got for example 6 records in my database, a table with 4 cols and 2
> rows should be generated, the last row will only have 2 cols with
> information...
>
> Like this:
>
> <table>
> <tr>
>   <td>Record1</td>
>   <td>Record2</td>
>   <td>Record3</td>
>   <td>Record4</td>
> </tr>
> <tr>
>   <td>Record5</td>
>   <td>Record6</td>
>   <td></td>
>  <td></td>
> </tr>
> </table>
>
> -----------------------------------
>
> This is what I have made so far:
> <table>
> <%
> set rsArt= server.CreateObject("adodb.recordset")
>   rsArt.Open SQL,conn
>
>      do until rsArt.EOF
>
>      rsArt.MoveNext
>      loop
>
>   rsArt.Close
> set rsArt = nothing
> %>
> </table>
>
> -----------------------------------
>
>
> Can someone please help me with this one???
>
> Regards,
> Øyvind Isaksen
>
>
Author
23 Mar 2005 4:56 PM
Phill. W
"Øyvind Isaksen" <oyv***@webressurs.no> wrote in message
news:%23N%238eY8LFHA.3228@TK2MSFTNGP12.phx.gbl...
> If I got for example 6 records in my database, a table with 4 cols
> and 2 rows should be generated, the last row will only have 2 cols
> with information...

Something like this?

    Do While Not rsArt.EOF
        RW "<tr>"
        For iCol = 1 To 4
            If Not rsArt.EOF Then
                RW "<td>" & celldata & "</td>"
                rsArt.MoveNext
            Else
                ' Empty cell after all the data
                RW "<td></td>"
            End If
        Next
        RW "</tr>"
    Loop

HTH,
    Phill  W.
Author
23 Mar 2005 5:18 PM
McKirahan
Show quote Hide quote
"Øyvind Isaksen" <oyv***@webressurs.no> wrote in message
news:#N#8eY8LFHA.3228@TK2MSFTNGP12.phx.gbl...
> Hi!
>
> I need to create a table with 4 cols and X rows based on the number
records
> in my database. I dont know how this can be done, mabye with an array?
>
> If I got for example 6 records in my database, a table with 4 cols and 2
> rows should be generated, the last row will only have 2 cols with
> information...
>
> Like this:
>
> <table>
> <tr>
>    <td>Record1</td>
>    <td>Record2</td>
>    <td>Record3</td>
>    <td>Record4</td>
> </tr>
> <tr>
>    <td>Record5</td>
>    <td>Record6</td>
>    <td></td>
>   <td></td>
> </tr>
> </table>
>
> -----------------------------------
>
> This is what I have made so far:
> <table>
> <%
> set rsArt= server.CreateObject("adodb.recordset")
>    rsArt.Open SQL,conn
>
>       do until rsArt.EOF
>
>       rsArt.MoveNext
>       loop
>
>    rsArt.Close
> set rsArt = nothing
> %>
> </table>
>
> -----------------------------------
>
>
> Can someone please help me with this one???
>
> Regards,
> Øyvind Isaksen
>
>

Will this help?


<table>
<tr>
<%
const rows = 4
dim i, j
    i = 0
    j = 0
set rsArt= server.CreateObject("adodb.recordset")
    rsArt.Open SQL,conn
do until rsArt.EOF
    i = i + 1
    if i > 1 and i Mod rows = 1 then
        j = 0
%>
</tr>
<tr>
<%  end if %>
  <td><%=rsArt("field_name")%></td>
<%
    j = j + 1
    rsArt.MoveNext
loop
    rsArt.Close
set rsArt = nothing

for i = 1 to rows - j
%>
  <td>&nbsp;</td>
<%
next
%>

Bookmark and Share