Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > MySQL
| Search | Today's Posts | Mark Forums Read
MySQL General discussion about the MySQL database.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the MySQL section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old July 4th, 2006, 11:54 PM
Registered User
Join Date: Jul 2006
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem with loop and array

I have a page that needs to display records in two columns. I have code written to pull the recordsets, turn it into an array, then divide it into two. It puts the first half in the first column, then the 2nd half in the 2nd column. There is a different number of records depending on the query. The problem is that when it gets to the second column, it is repeating the records.

Here is the code

dim aRS, x,y
aRS = RS.GetRows() ' Note this turns the Recordset into an array
RS.close ' We don't need the recordset anymore
x = ubound(aRS,2) / 2 ' get the midpoint of the array
y = 0
do while y < x
 if x + y < ubound(aRS,2) then
     response.write "<tr><td><b>" & aRS(1,y) & "</b>:&nbsp;" & aRS(2,y) & "</td><td><b>" & aRS(1,x+y) & ":</b>&nbsp;" & aRS(2,x+y) & "</td></tr>"
     response.write "<tr bgcolor=""white""><td>" & aRS(1,y) & "</td><td>&nbsp;</td></tr>"
  end if

   y = y + 1

  #2 (permalink)  
Old July 5th, 2006, 11:24 PM
Friend of Wrox
Join Date: Oct 2003
Location: colombo, WP, Sri Lanka.
Posts: 479
Thanks: 0
Thanked 3 Times in 3 Posts
Send a message via MSN to surendran Send a message via Yahoo to surendran

use this code...

<% x=2
    noofrows=reccount \ x
    balance=reccount mod x
 <table border="0" width="100%">
<%for i=1 to noofrows%>
<%for j=1 to x%>
<td width="<%=100/x%>%" valign="top">


<%for j=1 to balance%>
<td valign="top">


<td colspan="<%=(x-balance)%>" width></td>

(Anything is Possible)

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with Array and Loop ublend Classic ASP Professional 2 November 21st, 2007 07:50 AM
loop array problem dbrine Java Basics 2 June 15th, 2007 06:49 AM
Pass variables from array inside a loop dustygn PHP How-To 2 May 3rd, 2006 05:35 PM
create array for loop in FSO jfergy Classic ASP Professional 4 April 14th, 2006 09:59 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.