Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Display Records in a Table Horizontally

Posted on 2001-08-27
18
Medium Priority
?
310 Views
Last Modified: 2008-03-03
I want to display records in a table horizontally.
if number of records are even then it display correctly but if the number of records are odd then it gives error

Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.

code is

<%do while not rst1.EOF%>
     <TD><%=rst1.Fields ("pic_id")%></TD>
    <%if not rst1.EOF then%>
    <%rst1.MoveNext%>
    <TD><%=rst1.Fields ("pic_id")%></TD>
    <%end if%>
<%     rst1.MoveNext
loop
%>
0
Comment
Question by:fiaz1
  • 8
  • 4
  • 2
  • +3
18 Comments
 

Expert Comment

by:answerbank
ID: 6428036
Hi,

I dont find the need of the if statement in your code. Try this code instead.
<table>
<tr>
<%while not rst1.eof%>
    <TD><%=rst1.Fields ("pic_id")%></TD>
    <%rst1.movenext%>
<%wend%>
</tr>
</table>
regards,
answerbank
0
 

Author Comment

by:fiaz1
ID: 6428154
Actually this is not an actual code but this is my requirement i used a lots of table in <td> tag .
0
 
LVL 2

Expert Comment

by:turbosig
ID: 6428278
Let me know if you need more info, but use a loop and a counter.

Once you reach, X amount of records insert a </tr><tr> and start the process over.  Then when you hit an empty cell, i.e. your last row only has 3 cells, not for, insert an empty cell with the HTML code &nbsp;

<table><tr>
<%
do while not rst1.EOF
%>
x=1
For X = 1 to rst1.Count

if x=5 then
  </tr><tr>
   x=1
else  
<TD><%=rst1.Fields ("pic_id")%></TD>
end if
<%rst1.MoveNext%>
next

'You may want to consider .getrows here to build an array

'I have not tested this? I actually build an array.


0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:fiaz1
ID: 6428309
Actually this is not an actual code but this is my requirement i used a lots of table in <td> tag .
0
 
LVL 2

Expert Comment

by:turbosig
ID: 6428318
Please re-phrase your second Q? you posted the same sentence twice.
0
 
LVL 3

Accepted Solution

by:
Hornet241 earned 100 total points
ID: 6430102
Instead of this

   <%if not rst1.EOF then%>
   <%rst1.MoveNext%>
   <TD><%=rst1.Fields ("pic_id")%></TD>
   <%end if%>

try this

   <%if not rst1.EOF then exit do%>
   <%rst1.MoveNext%>
   <TD><%=rst1.Fields ("pic_id")%></TD>

0
 

Author Comment

by:fiaz1
ID: 6431014
here is the actual code

<div align="center">
      <center>
            <table border="0" cellpadding="0" cellspacing="0" height="87" align="center">
                  <tr>
                        <td rowspan="4" height="87" valign="bottom">
                              <table width="<%=session("framew1")%>" height="<%=session("frameh1")%>" border="0" cellpadding="0" cellspacing="0" align="center">
                                    <tr>
                                          <%if session("frame_id") then%>
                                                <td width="<%=session("framew")%>" height="<%=session("frameh")%>"><img src="<%=ltopc%>" width="<%=session("framew")%>" height="<%=session("frameh")%>"></td>
                                                <td width="<%=session("framew1")%>" height="<%=session("frameh")%>"><img src="<%=upper_f %>" width="<%=session("framew1")%>" height="<%=session("frameh")%>"></td>
                                                <td width="<%=session("framew")%>" height="<%=session("frameh")%>"><img src="<%=rtopc %>" width="<%=session("framew")%>" height="<%=session("frameh")%>"></td>
                                          <%end if%>
                                    </tr>
                                    <tr>
                                          <%if session("frame_id") then%>
                                                <td width="<%=session("framew")%>" height="<%=session("frameh1")%>"><img src="<%=lside %>" width="<%=session("framew")%>" height="<%=session("frameh1")%>"></td>
                                          <%end if%>
                                          <td align="center">
                                                <table background="<%=topmat_path%>" width="<%=session("topmatw")%>" height="<%=session("topmath")%>" border="0" cellpadding="0" cellspacing="0" align="center">
                                                      <tr><td align="center">
                                                            <table background="<%=midmat_path%>" width="<%=session("midmatw")%>" height="<%=session("midmath")%>" border="0" cellpadding="0" cellspacing="0" align="center">
                                                                  <tr><td align="center">
                                                                        <table background="<%=botmat_path%>" width="<%=session("botmatw")%>" height="<%=session("botmath")%>" border="0" cellpadding="0" cellspacing="0" align="center">
                                                                              <tr><td align="center">
                                                                                    <img src="<%=path_photo%>" width="<%=picw%>" height="<%=pich%>" align="center">
                                                                              </td></tr>
                                                                        </table>
                                                                  </td></tr>
                                                            </table>
                                                      </td></tr>
                                                </table>
                                          </td>
                                          <%if session("frame_id") then%>
                                                <td width="<%=session("framew")%>" height="<%=session("frameh1")%>"><img src="<%=rside %>" width="<%=session("framew")%>" height="<%=session("frameh1")%>"></td>
                                          <%end if%>
                                    </tr>
                                    <tr>
                                          <%if session("frame_id") then%>
                                                <td width="<%=session("framew")%>" height="<%=session("frameh")%>"><img src="<%=lbotc %>" width="<%=session("framew")%>" height="<%=session("frameh")%>"></td>
                                                <td width="<%=session("framew1")%>" height="<%=session("frameh")%>"><img src="<%=lower_f%>" width="<%=session("framew1")%>" height="<%=session("frameh")%>"></td>
                                                <td width="<%=session("framew")%>" height="<%=session("frameh")%>"><img src="<%=rbotc %>" width="<%=session("framew")%>" height="<%=session("frameh")%>"></td>
                                          <%end if%>
                                    </tr>
                              </table>
                              <td height="36"> </td>
                              <%if rst1.EOF then
                              rst1.MoveNext

'some asp code that get value in variables
%>
 %>
                              <td rowspan="4" height="87" valign="bottom">
                                    <table width="<%=session("framew1")%>" height="<%=session("frameh1")%>" border="0" cellpadding="0" cellspacing="0" align="center">
                                          <tr>
                                                <%if session("frame_id") then%>
                                                      <td width="<%=session("framew")%>" height="<%=session("frameh")%>"><img src="<%=ltopc%>" width="<%=session("framew")%>" height="<%=session("frameh")%>"></td>
                                                      <td width="<%=session("framew1")%>" height="<%=session("frameh")%>"><img src="<%=upper_f %>" width="<%=session("framew1")%>" height="<%=session("frameh")%>"></td>
                                                      <td width="<%=session("framew")%>" height="<%=session("frameh")%>"><img src="<%=rtopc %>" width="<%=session("framew")%>" height="<%=session("frameh")%>"></td>
                                                <%end if%>
                                          </tr>
                                          <tr>
                                                <%if session("frame_id") then%>
                                                      <td width="<%=session("framew")%>" height="<%=session("frameh1")%>"><img src="<%=lside %>" width="<%=session("framew")%>" height="<%=session("frameh1")%>"></td>
                                                <%end if%>
                                                <td align="center">
                                                      <table background="<%=topmat_path%>" width="<%=session("topmatw")%>" height="<%=session("topmath")%>" border="0" cellpadding="0" cellspacing="0" align="center">
                                                            <tr><td align="center">
                                                                  <table background="<%=midmat_path%>" width="<%=session("midmatw")%>" height="<%=session("midmath")%>" border="0" cellpadding="0" cellspacing="0" align="center">
                                                                        <tr><td align="center">
                                                                              <table background="<%=botmat_path%>" width="<%=session("botmatw")%>" height="<%=session("botmath")%>" border="0" cellpadding="0" cellspacing="0" align="center">
                                                                                    <tr><td align="center">
                                                                                          <img src="<%=path_photo%>" width="<%=picw%>" height="<%=pich%>" align="center">
                                                                                    </td></tr>
                                                                              </table>
                                                                        </td></tr>
                                                                  </table>
                                                            </td></tr>
                                                      </table>
                                                </td>
                                                <%if session("frame_id") then%>
                                                      <td width="<%=session("framew")%>" height="<%=session("frameh1")%>"><img src="<%=rside %>" width="<%=session("framew")%>" height="<%=session("frameh1")%>"></td>
                                                <%end if%>
                                          </tr>
                                          <tr>
                                                <%if session("frame_id") then%>
                                                      <td width="<%=session("framew")%>" height="<%=session("frameh")%>"><img src="<%=lbotc %>" width="<%=session("framew")%>" height="<%=session("frameh")%>"></td>
                                                      <td width="<%=session("framew1")%>" height="<%=session("frameh")%>"><img src="<%=lower_f%>" width="<%=session("framew1")%>" height="<%=session("frameh")%>"></td>
                                                      <td width="<%=session("framew")%>" height="<%=session("frameh")%>"><img src="<%=rbotc %>" width="<%=session("framew")%>" height="<%=session("frameh")%>"></td>
                                                <%end if%>
                                          </tr>
                                    </table>
                              </td>
                         <%end if%>
                  </tr>
            </table>
      </center>
</div>
<%
rst1.MoveNext
loop
%>

0
 
LVL 2

Assisted Solution

by:turbosig
turbosig earned 100 total points
ID: 6431918
Holy COW.. You are using more session objects than I have ever seen.  Ever thought of creating an array and storing that in the object?  Better that having 20+ session objects created??

Also, I see <-- rst1.MoveNext --> at the end of your code although I do not see a single reference to any DB fields.

If this is the actual code, I believe you are getting confused with oRS("xValue") and Session("xValue").

oRS("xValue") - Record set value

Session("xValue") - server side object

Also, why do you use dynamic values like (rside) for your images? do they change often?

Please advise if you have actually USED this code in production, to me it looks as if you would need 1 gig of memory to keep this baby going?
0
 

Author Comment

by:fiaz1
ID: 6435260
This is not complete code, DB fields are set above than this code. Actual requirment is I display dynamic images in horizantol format just like this
1      2
3      4
....

so for this we move cursor to next records in a do while loop.
let say

do while not rs.eof
display first record  rs.movenext()(here we move cursor to next record) display second record
rs.movenext
loop
(now at the end of loop we again move cursor to next record.)

the output is like this
1     2
3     4

but when the records are odd then problem occur.
 
0
 

Author Comment

by:fiaz1
ID: 6435363
This is not complete code, DB fields are set above than this code. Actual requirment is I display dynamic images in horizantol format just like this
1      2
3      4
....

so for this we move cursor to next records in a do while loop.
let say

do while not rs.eof
display first record  rs.movenext()(here we move cursor to next record) display second record
rs.movenext
loop
(now at the end of loop we again move cursor to next record.)

the output is like this
1     2
3     4

but when the records are odd then problem occur.
 
0
 

Author Comment

by:fiaz1
ID: 6435405
This is not complete code, DB fields are set above than this code. Actual requirment is I display dynamic images in horizantol format just like this
1      2
3      4
....

so for this we move cursor to next records in a do while loop.
let say

do while not rs.eof
display first record  rs.movenext()(here we move cursor to next record) display second record
rs.movenext
loop
(now at the end of loop we again move cursor to next record.)

the output is like this
1     2
3     4

but when the records are odd then problem occur.
 
0
 
LVL 2

Expert Comment

by:turbosig
ID: 6438141
Do what you are doing to build an array, then use a For - Next Loop and build the table.  If there is only 1 image on the row and the last array slot is empty, then just insert an blank <td>.
0
 

Author Comment

by:fiaz1
ID: 6439299
i think u do not understand my question.
problem in recordset not in table.
0
 

Author Comment

by:fiaz1
ID: 6637373
code is here

<%do while not rs.eof%>
<tr>
'first record
<td><%=rs("name")%></td>
<%rs.movenext%>
'second record
<td><%=rs("name")%></td>
</tr>
'for third record
<%rs.movenext
loop
%>

so if records are even then its ok
but if records are odd then first rs.movenext genrates error
"either end or before of files or records deleted"
0
 
LVL 3

Expert Comment

by:Hornet241
ID: 6642126
Add this

    <%do while not rs.eof%>
      <tr>
      'first record
        <td><%=rs("name")%></td>
        <%rs.movenext%>
*** If rs.eof Then Exit Do ****
        'second record
        <td><%=rs("name")%></td>
      </tr>
        'for third record
        <%rs.movenext
    loop%>

minus the ***'s

this will exit the loop if an EOF occurs in between the records
0
 
LVL 33

Expert Comment

by:hongjun
ID: 8755441
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
[split b/w turbosig(Assisted) and Hornet241(Accepted)]

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

hongjun
EE Cleanup Volunteer
0
 

Expert Comment

by:garnett-dickinson
ID: 26382665
Hi - I'd been searchiong for a simple answer to the horizontal looper from DB to HTML table and came uop with this very simple version - just change the iRecordsPerRow to the amount of records you want and it should do the rest! - no messing with cursers and move next blah,blah - keepin it simple!!
            <%
			'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'..---...-.--...-.-..--- ...-.--...-.-..---..---
'_____HORIZONTAL LOOPER - _____HORIZONTAL LOOPER - 			
	''Open the table
	Response.Write 	"<table width='1000' border='1' cellspacing='0' cellpadding='0'>"
	'Open the first row
	Response.Write "<TR>"	
	
	Dim iLoop 'Create a counter.
	iLoop = 0 'Set the counter to 1
	Dim iRecordsPerRow 
	''..---...-.--...-.-..--- 
	iRecordsPerRow = 4'Set this to the amount of columns you want in the table row
	Dim strRowFinisher 'Unless you fall lucky, you will need some <TD></TD> tags at the end of the last row to make the table correctly
	strRowFinisher = ""
	Dim iBackCount 'iBackCount takes the amount per row and subtracts one on each loop
	iBackCount = iRecordsPerRow

	'Create a recordset
	Set objRS = Server.CreateObject("ADODB.Recordset")
	
	'Open it
	objRS.Open strSQL, objConn
	
	'Start pouring the records out
	Do WHile Not objRS.EOF
	
	Response.Write "<td>" &  objRS("Product_ID") & "</td>"

	'Increment the loop by one
  	iLoop = (iLoop + 1)	
	iBackCount = (iBackCount - 1)
 		If (iLoop = iRecordsPerRow) Then 'We are at the end of the row so at the TR end of row and start of row
			Response.Write "</TR><TR>"
			iLoop = 0 'So reset the counter to 1
			iBackCount = iRecordsPerRow 'Reset iBackCount to the amount of records in a row
		End If
  	objRS.MoveNext
	Loop
	
	'Finish off the last row with the right amount of TD tage to complete the row
	'If iLoop is on zero this doesn';t need to happen
	If (iLoop <> 0) Then 'Do it
	Dim iCount 'Create a new counter
	For iCount = 1 To iBackCount 'Go from 1 to the amount generated by iBackCount
	strRowFinisher = (strRowFinisher & "<TD></TD>")
	'EG If we only have 2 records on the last row, iBackCount will = 3 and the strRowFinisher will be three sets of TD tags
	next
	Response.Write strRowFinisher
	End If
	
	'Write the end of the final row
	Response.Write "</TR>"
	'Close the table
	Response.Write "</TABLE>"

'END HORIZONTAL LOOPER - END HORIZONTAL LOOPER - END	'_________________________________________________________________'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  %>   

Open in new window

0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
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…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

885 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