Solved

Display Records in a Table Horizontally

Posted on 2001-08-27
18
294 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
 

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 25 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 25 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now