Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing a two column HTML table using GetRows() data. 2

Status
Not open for further replies.

reisende

Programmer
Mar 16, 2004
74
US
Hi everybody.

I've been trying to find the best way of splitting data from a GetRows() function into a two column HTML table but haven't been able to come up with anything myself or fin d much of use online. Maybe one of you guys have tackled a similar issue.

First of all, here's my code:

Code:
<% 
  strSQL = "SELECT * FROM SHOW_COUNTIES WHERE REGION_ID = " & regionId & ";"
  call getData(strSQL, rsTemp, "region")
  arrCounties = rsTemp.GetRows()
  
  for i = 0 to UBound(arrCounties,2)
%>				
<table width="98%" cellpadding="0" cellspacing="0">	
  <tr>
    <td colspan="2" class="countyHeader">CORA Clinics - <%= arrCounties(1,i) %> County<a name="<%= arrCounties(1,i) %>"></a></td>
  </tr>
  <tr>
    <td height="6"></td>
  </tr>
</table>
<table width="98%" style="margin: 0px 5px;">
  <tr>
    <td width="50%" valign="top" align="center"> 
<%
    strSQL2 = "SELECT CLINIC_ID, CLINIC_NAME FROM CLINICS WHERE CLINIC_COUNTY_ID = " & arrCounties(0,i) & ";"
	call getData(strSQL2, rsTemp2, "region")
	arrClinics = rsTemp2.GetRows()
	
	for c = 0  to UBound(arrClinics,2)
	  Response.Write("<table width='98%' cellpadding='0' cellspacing='0'>")
	  Response.Write("  <tr>")
	  Response.Write("    <td class='treemenu' width='9'><img src='../images/sm_arrow.gif' class='expand'></td>")
	  Response.Write("    <td class='treemenu'><a href='clinic_details.asp?clinicId="&arrClinics(0,c)&"'>"&arrClinics(1,c)&"</a></td>")
	  Response.Write("  </tr>")
	  Response.Write("</table>")
    next
%>
    </td>
    <td width="50%" valign="top" align="center"> 
    
    </td>
  </tr>
</table>
<p id="small">
<% 
  next
%>

What I want to do is print half of the returned records from the second GetRows() (the clinics) into the first column <td> and then print the rest into the second.

I can split them fine if the number of records returned is even, but if they are odd are want the larger number printed in the first column and the remainder in the second. For example, if nine records are returned I want 5 in the first and 4 and the second and so on.

I'm always looking for ways to make my code as efficient as possible so any suggestions/examples would be greatly appreciated.

Thanks.
 
I'm not sure I follow exactly what you want to do but maybe you can use math to help?

Assume x = 9

Do a "div" to get the number of rows:
x \ 2 = 4


Do a "mod" to find out if the number is even or odd (ie: result is 0 or 1):
x Mod 2 = 1
 
try something like this, i remove the the <td> that contains the arrow.gif but yoiu can adopt it


Code:
<%
  strSQL = "SELECT * FROM SHOW_COUNTIES WHERE REGION_ID = " & regionId & ";"
  call getData(strSQL, rsTemp, "region")
  arrCounties = rsTemp.GetRows()
  
  for i = 0 to UBound(arrCounties,2)
%>                
<table width="98%" cellpadding="0" cellspacing="0">    
  <tr>
    <td colspan="2" class="countyHeader">CORA Clinics - <%= arrCounties(1,i) %> County<a name="<%= arrCounties(1,i) %>"></a></td>
  </tr>
  <tr>
    <td height="6"></td>
  </tr>
</table>
<table width="98%" style="margin: 0px 5px;">
  <tr>
    <td width="50%" valign="top" align="center">
<%
    strSQL2 = "SELECT CLINIC_ID, CLINIC_NAME FROM CLINICS WHERE CLINIC_COUNTY_ID = " & arrCounties(0,i) & ";"
    call getData(strSQL2, rsTemp2, "region")
    arrClinics = rsTemp2.GetRows()

'column repeater-------------------------
NumColumns =2 'set amount of columns you want
NumRecords = ubound(arrClinics,2) + 1 

if NumRecords mod NumColumns = 0 then
    NumRows = NumRecords\NumColumns
Else
    NumRows = NumRecords\NumColumns + 1
End if    
      Response.Write("<table width='98%' cellpadding='0' cellspacing='0'>")
      Response.Write("  <tr>")
for RowCounter = 1 to NumRows

    For ColCounter = 0 to NumColumns-1
    
        if RowCounter + ColCounter * NumRows <= NumRecords then
		rowposition=RowCounter + ColCounter * NumRows-1

      Response.Write("<td class='treemenu'><a href='clinic_details.asp?clinicId="&arrClinics(0, rowposition)&"'>"&arrClinics(1, rowposition)&"</a></td>")

        Else             

	Response.Write("<td>&nbsp;</td>")
        end if 
    Next
      Response.Write("  </tr>")
Next
response.write "</table>"
'end -------------------------------
%>
   </td>
    <td width="50%" valign="top" align="center">
    
    </td>
  </tr>
</table>
<p id="small">
<%
  next
%>
 
this code has done the column repeater for me in that past but you are doing it within a loop so i don't know what the outcome will be
 
Thanks, guys.

Let me give it a try today and I'll let you know how it turns out.
 
OK, I was pretty close with what I started with but both of your suggestions helped point me in the right direction.

Here's what I ended up doing and everything appears to be working fine:

Code:
<% 
  strSQL = "SELECT * FROM SHOW_COUNTIES WHERE REGION_ID = " & regionId & ";"
  call getData(strSQL, rsTemp, "region")
  arrCounties = rsTemp.GetRows()
  
  for i = 0 to UBound(arrCounties,2)
%>				
<table width="98%" cellpadding="0" cellspacing="0">	 
  <tr>
    <td colspan="2" class="countyHeader">CORA Clinics - <%= arrCounties(1,i) %> County<a name="<%= arrCounties(1,i) %>"></a></td>
  </tr>
  <tr>
    <td height="6"></td>
  </tr>
</table>
<table width="98%" style="margin: 0px 5px;">
  <tr>
    <td width="50%" valign="top" align="center"> 
<%
    strSQL2 = "SELECT CLINIC_ID, CLINIC_NAME FROM CLINICS WHERE CLINIC_COUNTY_ID = " & arrCounties(0,i) & ";"
    call getData(strSQL2, rsTemp2, "region")
    arrClinics = rsTemp2.GetRows()
	
    numRecords = UBound(arrClinics,2) + 1
	
    if numRecords mod 2 = 0 then
      numRecords = (numRecords / 2) - 1
      columnStart = numRecords + 1
    else
      numRecords = numRecords / 2
      arrRecords = Split(numRecords, ".")
      numRecords = arrRecords(0)
      columnStart = numRecords + 1
    end if
	
    for c = 0 to numRecords
      Response.Write("<table width='98%' cellpadding='0' cellspacing='0'>")
      Response.Write("  <tr>")
      Response.Write("    <td class='treemenu' width='9'><img src='../images/sm_arrow.gif' class='expand'></td>")
      Response.Write("    <td class='treemenu'><a href='clinic_details.asp?clinicId="&arrClinics(0,c)&"'>"&arrClinics(1,c)&"</a></td>")
      Response.Write("  </tr>")
      Response.Write "</table>"
    next
%>
    </td>
    <td width="50%" valign="top" align="center">
<%
    for c = columnStart to UBound(arrClinics,2)
      Response.Write("<table width='98%' cellpadding='0' cellspacing='0'>")
      Response.Write("  <tr>")
      Response.Write("    <td class='treemenu' width='9'><img src='../images/sm_arrow.gif' class='expand'></td>")
      Response.Write("    <td class='treemenu'><a href='clinic_details.asp?clinicId="&arrClinics(0,c)&"'>"&arrClinics(1,c)&"</a></td>")
      Response.Write("  </tr>")
      Response.Write "</table>"
    next
%>						  
    <td>
    </td>
  </tr>
</table>
<p id="small">
<% 
  next
%>

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top