Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > Generate a table with ASP

Reply
Thread Tools

Generate a table with ASP

 
 
Řyvind Isaksen
Guest
Posts: n/a
 
      03-23-2005
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


 
Reply With Quote
 
 
 
 
Ray Costanzo [MVP]
Guest
Posts: n/a
 
      03-23-2005
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

"Řyvind Isaksen" <(E-Mail Removed)> wrote in message
news:%23N%(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
 
 
 
Phill. W
Guest
Posts: n/a
 
      03-23-2005
"Řyvind Isaksen" <(E-Mail Removed)> wrote in message
news:%23N%(E-Mail Removed)...
> 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.


 
Reply With Quote
 
McKirahan
Guest
Posts: n/a
 
      03-23-2005
"Řyvind Isaksen" <(E-Mail Removed)> wrote in message
news:#N#(E-Mail Removed)...
> 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
%>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Failed to generate a user instance of SQL Server. Only an integratedconnection can generate a user instance. Harlan Messinger ASP .Net 2 03-28-2010 06:51 PM
how to generate html table from "table" data? petr.jakes.tpc@gmail.com Python 9 12-28-2007 09:44 AM
How to generate warnings when How generate a warning when int is converted to bool or vice versa? PengYu.UT@gmail.com C++ 3 04-06-2006 11:24 PM
How to generate variable labels for same component within a generate loop Weng Tianxiang VHDL 5 02-16-2006 01:45 PM
Could not load type VTFixup Table from assembly Invalid token in v-table fix-up table. David Williams ASP .Net 2 08-12-2003 07:55 AM



Advertisments