Solved

Classic ASP - Display data in three columns table in a loop,

Posted on 2009-04-14
26
2,116 Views
Last Modified: 2012-05-06
Hi there,

I need a little help, i'm developing a website for myself. I need help in displaying data in three columns with multiple rows, in a loop form.

i'm displaying images, which the user adds via a content management system, and on the website it must display the images in three columns in each row.

any help well appreciated. thank you.

Fezi
0
Comment
Question by:Fezi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 11
  • 9
  • 6
26 Comments
 
LVL 5

Expert Comment

by:Abiel de Groot
ID: 24138761
How are you collecting the data? are you using getrows() ?

A.
0
 

Author Comment

by:Fezi
ID: 24139839
See below how i'm displaying the data from the database.
<table class="fontonly" cellpadding="5" cellspacing="5">
<%
set objRS4 = Server.CreateObject("ADODB.Recordset")
sql4="select * from pages where category='Personal Project' and active=1"
set objRS4 = db.execute(sql4)
 
if not objRS4.eof then 
	do while not objRS4.eof 
%>
<tr valign="top">
<td><img src="secure/<%=objRS4("image")%>" alt="<%=objRS4("alt")%>" title="<%=objRS4("alt")%>" width="235" height="171"></td>
<td>
<a href="#" style="font-family:verdana;font-size:12px;"><%=objRS4("project_name")%></a>
<br><br>
<%=objRS4("meta_description")%>
</td>
</tr>
<%
	objRS4.MoveNext
loop
end if
%>
</table>

Open in new window

0
 
LVL 5

Expert Comment

by:Abiel de Groot
ID: 24140176

Use arrays. they are easier to manipulate and a more efficient on the server.
This populates the array.
-----------------------------
<%

Dim MyArray

set objRS4 = Server.CreateObject("ADODB.Recordset")
sql4="select * from pages where category='Personal Project' and active=1"
set objRS4 = db.execute(sql4)
if not objRS4.eof then
MyArray = rsData.GetRows()
End if
objRS4.Close
Set objRS4 = Nothing

%>
0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 

Author Comment

by:Fezi
ID: 24140308
hi there,

i'm pretty new to asp, so i have no idea wat GetRows() is, but will do research, but i stil cant seem to figure out how i can get this done, any chance you can do this for me please, access database wil be fine,

thank you
0
 
LVL 5

Expert Comment

by:Abiel de Groot
ID: 24140341
Change the following line in the code.
sql4="select * from pages where category='Personal Project' and active=1"

To

sql4="select image, alt, project_name, meta_description from pages where category='Personal Project' and active=1"

A.

I will show you how to do it. The rest is up to you.

0
 
LVL 5

Expert Comment

by:Abiel de Groot
ID: 24140360
Here is your table.

<table class="fontonly" cellpadding="5" cellspacing="5">
<%
If IsArray(MyArray) Then
For i = 0 To Ubound(MyArray,2)
%>
<tr valign="top">
<td><img src="secure/<%=MyArray(0,i%>" alt="<%=MyArray(2,i%>" title="<%=MyArray(2,i%>" width="235" height="171"></td>
<td>
<a href="#" style="font-family:verdana;font-size:12px;"><%=MyArray(3,i%></a>
<br><br>
<%=MyArray(4,i%>
</td>
</tr>
<%
Next
End If
%>
</table>
0
 
LVL 5

Expert Comment

by:Abiel de Groot
ID: 24140372
You may need to declare

Dim i

Good luck A.

0
 

Author Comment

by:Fezi
ID: 24140473
See code below, is that how its suppose to be. I think i'm a little confused.

<table class="fontonly" cellpadding="5" cellspacing="5">
<%
 
set objRS4 = Server.CreateObject("ADODB.Recordset")
sql4="select * from pages where category='Personal Project' and active=1"
set objRS4 = db.execute(sql4)
 
Dim i
 
If IsArray(MyArray) Then 
For i = 0 To Ubound(MyArray,2)
%>
<tr valign="top">
<td><img src="secure/<%=MyArray(0,i)%>" alt="<%=MyArray(2,i)%>" title="<%=MyArray(2,i)%>" width="235" height="171"></td>
<td>
<a href="#" style="font-family:verdana;font-size:12px;"><%=MyArray(3,i)%></a>
<br><br>
<%=MyArray(4,i)%>
</td>
</tr>
<%
Next
End If
%>
</table>

Open in new window

0
 
LVL 5

Expert Comment

by:Abiel de Groot
ID: 24140695
Always put your asp code within the head. Open data connections ,get your data, close teh connection and set to nothing.

You then have teh array of what you need. simply call it in you html.

I have the page for you below.

A.
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
Dim MyArray, i
 
set objRS4 = Server.CreateObject("ADODB.Recordset")
sql4="select image, alt, project_name, meta_description from pages where category='Personal Project' and active=1"
set objRS4 = db.execute(sql4)
if not objRS4.eof then 
MyArray = rsData.GetRows()
End if
objRS4.Close
Set objRS4 = Nothing
%>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
 
<body>
 
<table class="fontonly" cellpadding="5" cellspacing="5">
<%
If IsArray(MyArray) Then 
For i = 0 To Ubound(MyArray,2)
%>
<tr valign="top">
<td><img src="secure/<%=MyArray(0,i%>" alt="<%=MyArray(2,i%>" title="<%=MyArray(2,i%>" width="235" height="171"></td>
<td>
<a href="#" style="font-family:verdana;font-size:12px;"><%=MyArray(3,i%></a>
<br><br>
<%=MyArray(4,i%>
</td>
</tr>
<%
Next
End If
%>
</table>
 
</body>
</html>

Open in new window

0
 
LVL 31

Expert Comment

by:Wayne Barron
ID: 24140899
Are you wanting to display data across 3 columns.
And multiple rows depending on the data that is within the table?
If so.
Try this.

Carrzkiss
<table width="900" border="0" bgcolor="LightSteelBlue" cellspacing="1" align="center">
  <tr>
   <%While Not objRS4.EOF
   if n mod 1 = 0 then%>
 
 
    <td width="50"><img src="secure/<%=objRS4("image")%>" alt="<%=objRS4("alt")%>" title="<%=objRS4("alt")%>" width="235" height="171"></td>
    <td width="50"><%=objRS4("meta_description")%></td>
    <td width="50"><%=objRS4("meta_description")%></td>
>  </tr>
  
  <%
   end if
    n = n + 1
    objRS4.MoveNext
    Wend
    objRS4.Close
    Set objRS4=Nothing
%>
</table>

Open in new window

0
 

Author Comment

by:Fezi
ID: 24141351
Hello there,

I have tested the two solutions, none of them seem to work.

Carrzkiss - i like your solutions, its a lot simpler to understand, but it does not seem to work. any ideas to what i am doing wrong.
0
 
LVL 31

Expert Comment

by:Wayne Barron
ID: 24141428
Fezi.
Does your table consist of:

image
alt
project_name
meta_description

OK.
This is what I am thinking that you are wanting to do.
Let me know if this is it?

You have multiple rows of data in your table.
You want to have all rows to display within' the table?

Is this correct?
If not, please instuct as to what you are wanting.

I am going to assume that I am correct, and I am going to put together a working demo for you
WIth my thoughts.

Let me know?
Carrzkiss


0
 
LVL 5

Expert Comment

by:Abiel de Groot
ID: 24141492
Sorry I forgot about the 3 per row issue.

Regards

I have amened my option below.

Kind regards

A.
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
Dim MyArray, i, NumCount, NumPerRow, BolClosed
 
NumPerRow = 4 'Amend as needed
 
set objRS4 = Server.CreateObject("ADODB.Recordset")
sql4="select image, alt, project_name, meta_description from pages where category='Personal Project' and active=1"
set objRS4 = db.execute(sql4)
if not objRS4.eof then 
MyArray = rsData.GetRows()
End if
objRS4.Close
Set objRS4 = Nothing
%>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
 
<body>
 
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<%
 
If IsArray(MyArray) Then 
For i = 0 To Ubound(MyArray,2)
 
NumCount = i mod NumPerRow
If NumCount = 1 Then
BolClosed = False
%>
<tr>
    <td>
<!-- This is your table -->
<table class="fontonly" cellpadding="5" cellspacing="5">
<tr valign="top">
<td><img src="secure/<%=MyArray(0,i%>" alt="<%=MyArray(2,i%>" title="<%=MyArray(2,i%>" width="235" height="171"></td>
<td>
<a href="#" style="font-family:verdana;font-size:12px;"><%=MyArray(3,i%></a>
<br><br>
<%=MyArray(4,i%>
</td>
</tr>
</table>
<!-- End Table -->
</td>
<%
Else
%>
<td>
<!-- This is your table -->
<table class="fontonly" cellpadding="5" cellspacing="5">
<tr valign="top">
<td><img src="secure/<%=MyArray(0,i%>" alt="<%=MyArray(2,i%>" title="<%=MyArray(2,i%>" width="235" height="171"></td>
<td>
<a href="#" style="font-family:verdana;font-size:12px;"><%=MyArray(3,i%></a>
<br><br>
<%=MyArray(4,i%>
</td>
</tr>
</table>
<!-- End Table -->
</td>
<%
End If
If NumCount = 0 Then
BolClosed = True
%>
</tr>
<%
End If
Next
If BolClosed = False Then 'close the table row.
%>
</tr>
<%
End if
%>
</table>
</body>
</html>

Open in new window

0
 
LVL 5

Expert Comment

by:Abiel de Groot
ID: 24141503
@Fezi

What error are you getting with my page?

A.
0
 
LVL 5

Expert Comment

by:Abiel de Groot
ID: 24141510
Change this value from 4 to 3

NumPerRow = 4 'Amend as needed


A.
0
 

Author Comment

by:Fezi
ID: 24141629
Hi Carrzkiss,

yes, that is partically correct.

I have a lot of data in the database that i want to display in a HTML table. I want each record in the database to be displayed in columns.

i have in the database are the following tables:

image
alt
project_name
meta_description

Each record should be displayed in columns. I want to display on the page a table that consists of 2 columns by multiple rows.

Let me know if you need further clarification.

Fezi
0
 
LVL 31

Expert Comment

by:Wayne Barron
ID: 24141678
0
 
LVL 5

Expert Comment

by:Abiel de Groot
ID: 24141713
>>I have a lot of data in the database that i want to display in a HTML table

Then I would Use arrays, or your page will be much slower to load... Think about it. You are going to open the database and one loop by one loop create yuor HTML to display the data. When all that is fnished you then close the database.

In arrays you open teh data connection get your data then close the data connection. It goes home and only then do you work with the array.

Just trying to help.

Kind regards

A.
0
 

Author Comment

by:Fezi
ID: 24141969
Hi there,

Carrzkiss - I already have done what you did, but you know those images you have i want them in 3 columns aswell as the text you have...

A - I have tried your solution, but i'm getting an error with 'Object Required'

www.farazshafiq.co.uk/projects.asp

Check that url.. rather than having those images in rows, i want them in seperate columns 3 columns by multiple rows...


0
 
LVL 31

Assisted Solution

by:Wayne Barron
Wayne Barron earned 500 total points
ID: 24142056
fezi
You stated:
>>>> I want to display on the page a table that consists of 2 columns by multiple rows.

Please explain what it is that you are wanting?
Do you want it to be:
Image | Image | Image
info    | info    | info  

Image | Image | Image
info    | info    | info  
exc......

Please explain?
Carrzkiss
0
 

Author Comment

by:Fezi
ID: 24142093
hi carrzkiss,

I am really sorry for the typo.. thats correct, thats what i need.

Image | Image | Image
info    | info    | info  

Image | Image | Image
info    | info    | info  
exc......

Let me know if you need more clarification?
0
 
LVL 5

Expert Comment

by:Abiel de Groot
ID: 24142232
A - I have tried your solution, but i'm getting an error with 'Object Required'

This is your data object. you are not callinf that correctly. chech which line and tell me what is says.

A.
0
 
LVL 31

Accepted Solution

by:
Wayne Barron earned 500 total points
ID: 24142290
0
 

Author Comment

by:Fezi
ID: 24142450
Hi,

That is perfect.. Thank you soo much Wayne, I really don't know how you have done it, but it's perfect. Thank you.


Fezi
0
 

Author Closing Comment

by:Fezi
ID: 31569904
Once again Carrzkiss has proved himself to be a GURU.. Carrzkiss sure knows what he is doing ! A ++
0
 
LVL 31

Expert Comment

by:Wayne Barron
ID: 24142873
your welcome.
It is not that hard really.
I am sure that you will understand the code once you dive into it.

Good Luck
Carrzkiss
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

628 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