Click to See Complete Forum and Search --> : formatting records display


janice
06-12-2004, 10:40 PM
Hi all,
I have a code that searches the database for 2 fields.
Field1 is called ID and field 2 is an image.
Even though the ID field is a text field, it can easily be changed to number.

The way it works currently is when a record is inserted into a database, and id is 1 (as an example), that id can be associated with 4 images.

So when the database is queried for an id 1, record is displayed like this:

ID Images
1 image1
1 image2
1 image3
1 image4

So I was just wandering if there is anyway to format the display to look like this:

ID Images
_______________________
1 image1
image2
image3
image4
______________________

I hope I am clear with what I am looking for

This is my current code:

<table border="1" width="90%">
<tr>
<th>ID</th>
<th>Image</th>
</tr>
<%
Do While Not rstSearch.EOF And rstSearch.AbsolutePage = iPageCurrent
%>
<tr>
<td><%= rstSearch("ID").Value %></td>
<td>
<%
Response.Write "<a href=""Findfile.asp?siteCode=" & rstSearch("ID") & """>"
Response.Write rstSearch("FileName") & "</a>"
%>
</td>
</tr>
<%

rstSearch.MoveNext
Loop
%>
</table>

Thanks again for all the help in this forum

buntine
06-13-2004, 05:21 AM
You could use an incrementing variable to determine whether the ID should be displayed or not.

Dim intCount
intCount = 0

Do While Not rstSearch.EOF And rstSearch.AbsolutePage = iPageCurrent
intCount = intCount + 1
%>
<tr>
<%
If intCount = 1 Then
Response.Write ("<td>" & rstSearch("ID").Value & "</td>")
Else
Response.Write ("<td></td>")
End If
%>
<td>
<%
Response.Write "<a href=""Findfile.asp?siteCode=" & rstSearch("ID") & """>"
Response.Write rstSearch("FileName") & "</a>"
%>
</td>
</tr>
<%

rstSearch.MoveNext
Loop

I hope i understood correctly.

Regards,
Andrew Buntine.

janice
06-13-2004, 07:09 AM
Thanks very much for your response, Andrew.

What I really wanted was to show only one ID on one cell and the all the records associated with it.
It's almost like saying colspan=4
This way, since the maximum number of files that can be associated with an ID is 4, you have once cell containing the id and one or more cells containing the files associated with that ID.
What did hides the ID value and we don't want that.

Basically, it looks back to have to repeat the ID numbers 2, 3 or 4 times.

We just want to show only one ID value and then show all the files associated with it.
Hope this is a bit clearer.

buntine
06-13-2004, 08:11 AM
Ahh, i left out some code by accident. I forgot to declare and increment the variable. Try the code again (i have edited it)

Regards.

janice
06-13-2004, 09:04 AM
Andrew, you are awesome, you are absolutely amazing!!
It works like a dream.
5 gloves to you!!!! :)

Thank you.

buntine
06-13-2004, 09:34 AM
Thanks. ;) Glad to help you out.

janice
06-13-2004, 02:10 PM
hi Andrew,
we have got a little problem.
The code is not breaking.
For instance,

ID Images
1 image1
1 image2
1 image3
1 image4

If I add another record with say ID 2,

instead of something like this:

ID Images
ID Images
1 image1
1 image2
1 image3
1 image4
______________________
2 image1
2 image2
2 image3

I get:

ID Images
ID Images
1 image1
1 image2
1 image3
1 image4

image1
image2
image3


As you can see, the new image files get added to the first ID, instead breaking it into a new table cell.

Am I making sense?h

buntine
06-13-2004, 08:45 PM
Im a little confused.. Why do you want your table to look like this? Didnt you want to stop the ID from being shown in each cell?

ID Images
ID Images
1 image1
1 image2
1 image3
1 image4
______________________
2 image1
2 image2
2 image3

Regards.

janice
06-14-2004, 07:18 AM
sorry if I confused you.
Our ID has a one to many relationship with the image files.
In other words, when you hit the submit key to store a record on our database, chances are that one id could have one or more images stored on the database.
For example, if I have one id number 1, that Id could be associated with 3 images.
So if I perform a query and say select id, image from mytable where id is 1,
I would get something like
id images

1 image1
----------------------
1 image2
----------------------
1 image3
----------------------

if I store another record on our database, that record would have id number 2 which would have one or more images associated with it.

So again it would look like this:

id images

2 image1
----------------------
2 image2
----------------------

So rather than have images id one listed 3 times or id 2 listed 2 times or id 3 listed 4 times etc,

I would love to have id 1 listed once and them have all the images associated with it listed as many times like this:

1 image1
image2
image3
----------------------

You see looking at above, there are 3 images listed.
So rather than list id 3 times, id is listed only once.
This applies to any other ids that have more than 1 image.

Hope it is clear this time.

Thanks for all the help.

buntine
06-14-2004, 07:25 AM
I think your going to have to create a new recordSet for each ID, each time the Loop iterates. So you can display all the images for ID #1, iterate the loop, display all the images for ID # 2, iterate the loop, etc, etc.

I understand what your problem is, though, i dont think i will be able to come up with an answer from the top of my head. I would need to be in front of the machine with all the files.

Regards,
Andrew Buntine.

simflex
06-14-2004, 10:14 AM
If it's ok with you guys, I can help.

Do While Not rstSearch.EOF And rstSearch.AbsolutePage = iPageCurrent
%>
<tr>
<%
siteCode = rstSearch("siteCode").Value
If siteCode <> oldid then
Response.Write ("<td>" & rstSearch("siteCode").Value & "</td>")
Else
Response.Write ("<td></td>")
End If
oldid = siteCode
%>
<td>
<%
Response.Write "<a href=""Findfile.asp?siteCode=" & rstSearch("siteCode") & """>"
Response.Write rstSearch("FileName") & "</a>"
%>
</td>
</tr>
<%

rstSearch.MoveNext
Loop
%>

I noticed that id and sitecode are used interchangeably.
I managed a little consistency but if indeed you want it the way you had it before, then change them back but this should solve your problem.
I highlighted the major changes.

buntine
06-14-2004, 11:27 AM
Good suggestion, Simflex.

janice
06-14-2004, 12:01 PM
wee-oh, it is working!!
It's working real good.
I have been testing it for the last 20 minutes and I have tested every scenario and it works GREAT!

Thanks Simflex very, very much.
Andrew, thanks also for all your efforts.
You all are doing a fantastic job here in this forum.