Solved

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

Posted on 2009-04-14
26
1,863 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
  • 11
  • 9
  • 6
26 Comments
 
LVL 5

Expert Comment

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

A.
0
 

Author Comment

by:Fezi
Comment Utility
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
Comment Utility

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
 

Author Comment

by:Fezi
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
You may need to declare

Dim i

Good luck A.

0
 

Author Comment

by:Fezi
Comment Utility
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
Comment Utility
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 30

Expert Comment

by:Wayne Barron
Comment Utility
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
Comment Utility
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 30

Expert Comment

by:Wayne Barron
Comment Utility
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
Comment Utility
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 5

Expert Comment

by:Abiel de Groot
Comment Utility
@Fezi

What error are you getting with my page?

A.
0
 
LVL 5

Expert Comment

by:Abiel de Groot
Comment Utility
Change this value from 4 to 3

NumPerRow = 4 'Amend as needed


A.
0
 

Author Comment

by:Fezi
Comment Utility
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 30

Expert Comment

by:Wayne Barron
Comment Utility
0
 
LVL 5

Expert Comment

by:Abiel de Groot
Comment Utility
>>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
Comment Utility
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 30

Assisted Solution

by:Wayne Barron
Wayne Barron earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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 30

Accepted Solution

by:
Wayne Barron earned 500 total points
Comment Utility
0
 

Author Comment

by:Fezi
Comment Utility
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
Comment Utility
Once again Carrzkiss has proved himself to be a GURU.. Carrzkiss sure knows what he is doing ! A ++
0
 
LVL 30

Expert Comment

by:Wayne Barron
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

744 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

19 Experts available now in Live!

Get 1:1 Help Now