Forum Moderators: open

Message Too Old, No Replies

new line how too

         

stevelibby

3:02 pm on Mar 23, 2006 (gmt 0)

10+ Year Member



hi all
i want to return a set of db results on my page, however i want to the text to be able to automatically go to the next line once the width has been used up.
here is my code:

<table border="0" cellpadding="0" cellspacing="0" width="780" id="table1">
<tr>
<% ' cycle through the record set and display each row results
do until objRS.EOF %>
<td><%= objRS ("County")%>, </td>
<% ' increment record position with MoveNext method
objRS.MoveNext
<!-- next row=next record -->
loop
%>

</tr>
</table>

How can i do this?

txbakers

4:05 pm on Mar 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



that's a bit tricky since people will set their browser width however they like it.

you can set a fixed number of columns per <tr> and count the columns so that if you reach the limit, then you would start a new <tr>.

I handle this many times - lists of data in three columns. I take a RecordCount of the number of returned entries, divide by 3 (or 5 if it's a 5 column table) and run a loop up to that number, with the MoveNext() inside each <td>. After each data I use <br> to go to the next line.

Hope that makes sense. I can post some code if you want but i'd have to clean up quite a bit of extra stuff in there first.

stevelibby

4:24 pm on Mar 23, 2006 (gmt 0)

10+ Year Member



hi
if you would not mind posting the code that would be great.

txbakers

10:11 pm on Mar 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



OK here goes:

first I run the query to get my data, then I get the number of records and set variables for my column record numbers (forgive my goofy variable names):


var numstu = rsGaveForm.RecordCount;
var sally = Math.round(numstu/3);
var betty = sally * 2;

then, down where the columns start it looks like this (lots stripped out for clarity)

the first column goes from record count 0 to "sally"

<tr>
<td>
<% if (rsGaveForm.EOF) { %>
&nbsp;
<% } else { %>
<% for (var i=0; i < sally ; i++) { %>
<%=rsGaveForm("name")%> <br>
<% rsGaveForm.MoveNext();
if (rsGaveForm.EOF){break} %>
<% } %><% } %>
</td>

the second column goes from sally to betty

<td>
<% if (rsGaveForm.EOF) { %> &nbsp;
<% } else { %>
<% for (var i=sally ; i < betty ; i++) { %>
<%=rsGaveForm("name")%><br>
<% rsGaveForm.MoveNext();
if (rsGaveForm.EOF){break} %>
<% } %><% } %>
</td>

and finally the third column goes from betty to numstu

<td>
<% if (rsGaveForm.EOF) { %>&nbsp;
<% } else { %>
<% for (var i=betty ; i < numstu ; i++) { %>
<%=rsGaveForm("name")%><br>
<% rsGaveForm.MoveNext();
if (rsGaveForm.EOF){break} %>
<% } %>
<% } %>

If you need five columns I do it a bit diferently and code left to right rather than in columns, doing a bunch of that same code in each column, but also checking for the record number, and if a multiple of 5 I start a new <tr>

a bit complicated.

I left in the bit about checking first for EOF on each column just as a reminder.

Hope that mess is clear.