473,796 Members | 2,425 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Displaying complex one to many relationship

<Mental block>

I want to display a kind of two-tier one-to-many relationship, for
which, in the olden days, I would have used a series of nested loops
and multiple calls to the db.

Here's the trimmed down code so far:

<%
sql = "SELECT StoryType.Story Type, Articles.Articl eID, Articles.Title,
Authors.Initial s, Authors.AuthorN ame FROM StoryType INNER JOIN (Authors
INNER JOIN (Articles INNER JOIN ArticleAuthors ON Articles.Articl eID =
ArticleAuthors. ArticleID) ON Authors.AuthorI D =
ArticleAuthors. AuthorID) ON StoryType.Story TypeID =
Articles.StoryT ypeID"

currentstorytyp e = ""
currentid = ""
s = ""
set rs = objconnection.e xecute(sql,,4)
arr = rs.getrows()
rs.close : set rs = nothing
for i = 0 to ubound(arr,2)
if arr(0,i) <> currentstorytyp e then
s = s & vbcrlf & vbcrlf & "<h5>" & arr(0,i) & "S</h5>" & vbcrlf
currentstorytyp e = arr(0,i)
end if
if arr(1,i) <> currentid then
s = s & "<p>" & arr(2,i) & "<br />" & vbcrlf
currentid = arr(1,i)
end if
s = s & arr(3,i) & " " & arr(4,i) & ", "
next
response.write s
%>

This displays the db content as follows:

STORYTYPE
Article title
Author 1, Author 2, Author 3,

Article title
Author 1, Author2,

STORYTYPE
Article title
Author 1,

Article Title
Author 1, Author 2, Author 3, Author 4,

This all works fine - except for one thing - I am having a real mental
block when it comes to identifying where the author list for each title
ends, so that I don't display a comma, and can close that section off
with a "</p>".

Suggestions, anyone?

Cheers

--
Mike Brind

Mar 10 '06 #1
2 1358

"Mike Brind" <pa*******@hotm ail.com> wrote in message
news:11******** **************@ j52g2000cwj.goo glegroups.com.. .
<Mental block>

I want to display a kind of two-tier one-to-many relationship, for
which, in the olden days, I would have used a series of nested loops
and multiple calls to the db.

Here's the trimmed down code so far:

<%
sql = "SELECT StoryType.Story Type, Articles.Articl eID, Articles.Title,
Authors.Initial s, Authors.AuthorN ame FROM StoryType INNER JOIN (Authors
INNER JOIN (Articles INNER JOIN ArticleAuthors ON Articles.Articl eID =
ArticleAuthors. ArticleID) ON Authors.AuthorI D =
ArticleAuthors. AuthorID) ON StoryType.Story TypeID =
Articles.StoryT ypeID"

currentstorytyp e = ""
currentid = ""
s = ""
set rs = objconnection.e xecute(sql,,4)
arr = rs.getrows()
rs.close : set rs = nothing
for i = 0 to ubound(arr,2)
if arr(0,i) <> currentstorytyp e then
s = s & vbcrlf & vbcrlf & "<h5>" & arr(0,i) & "S</h5>" & vbcrlf
currentstorytyp e = arr(0,i)
end if
if arr(1,i) <> currentid then
s = s & "<p>" & arr(2,i) & "<br />" & vbcrlf
currentid = arr(1,i)
end if
s = s & arr(3,i) & " " & arr(4,i) & ", "
next
response.write s
%>

This displays the db content as follows:

STORYTYPE
Article title
Author 1, Author 2, Author 3,

Article title
Author 1, Author2,

STORYTYPE
Article title
Author 1,

Article Title
Author 1, Author 2, Author 3, Author 4,

This all works fine - except for one thing - I am having a real mental
block when it comes to identifying where the author list for each title
ends, so that I don't display a comma, and can close that section off
with a "</p>".

Suggestions, anyone?

Cheers

--
Mike Brind


Mike,

Use a seperate string variable to build up the line of authors. When you
detect the rowset has move on to the next article append the line to the
string containing the html so far (or send directly to Response.Write (why
aren't you doing that?)) using:-

If sLine <> "" Then
s = s & Left(sLine,Len( sLine) - 2)
sLine = ""
End If

You could use a similar approach to building up the set of articles under
storytypes (all this string concatenation isn't good for VBScripts health).

Anthony.

Mar 10 '06 #2

Anthony Jones wrote:
"Mike Brind" <pa*******@hotm ail.com> wrote in message
news:11******** **************@ j52g2000cwj.goo glegroups.com.. .
<Mental block>

I want to display a kind of two-tier one-to-many relationship, for
which, in the olden days, I would have used a series of nested loops
and multiple calls to the db.

Here's the trimmed down code so far:

<%
sql = "SELECT StoryType.Story Type, Articles.Articl eID, Articles.Title,
Authors.Initial s, Authors.AuthorN ame FROM StoryType INNER JOIN (Authors
INNER JOIN (Articles INNER JOIN ArticleAuthors ON Articles.Articl eID =
ArticleAuthors. ArticleID) ON Authors.AuthorI D =
ArticleAuthors. AuthorID) ON StoryType.Story TypeID =
Articles.StoryT ypeID"

currentstorytyp e = ""
currentid = ""
s = ""
set rs = objconnection.e xecute(sql,,4)
arr = rs.getrows()
rs.close : set rs = nothing
for i = 0 to ubound(arr,2)
if arr(0,i) <> currentstorytyp e then
s = s & vbcrlf & vbcrlf & "<h5>" & arr(0,i) & "S</h5>" & vbcrlf
currentstorytyp e = arr(0,i)
end if
if arr(1,i) <> currentid then
s = s & "<p>" & arr(2,i) & "<br />" & vbcrlf
currentid = arr(1,i)
end if
s = s & arr(3,i) & " " & arr(4,i) & ", "
next
response.write s
%>

This displays the db content as follows:

STORYTYPE
Article title
Author 1, Author 2, Author 3,

Article title
Author 1, Author2,

STORYTYPE
Article title
Author 1,

Article Title
Author 1, Author 2, Author 3, Author 4,

This all works fine - except for one thing - I am having a real mental
block when it comes to identifying where the author list for each title
ends, so that I don't display a comma, and can close that section off
with a "</p>".

Suggestions, anyone?

Cheers

--
Mike Brind

Mike,

Use a seperate string variable to build up the line of authors.


Gotcha. That would be the simplest thing :-)

When you detect the rowset has move on to the next article append the line to the
string containing the html so far (or send directly to Response.Write (why
aren't you doing that?))
I would normally, but the code I didn't include (because it isn't
germane to my headache) would show that this is part of a function that
rebuilds an application level variable. I cache this because the value
of it will only ever change about once every two or three months (or
when I have to make the odd alteration in between).

using:-
If sLine <> "" Then
s = s & Left(sLine,Len( sLine) - 2)
sLine = ""
End If

Yep - I see. Knock off the final comma and space.
You could use a similar approach to building up the set of articles under
storytypes (all this string concatenation isn't good for VBScripts health).


Agreed. In most cases.

Thank you

--
Mike Brind

Mar 10 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1623
by: middletree | last post by:
I tried posting this to the SQL Server programming group, but then thought more about it, and thought it was more of an ASP question. If you want the original long description, it's below. But the short version is, I have created a new table to resolve a many-to-many relationship in my tech support ticket-tracking app. When I do a query which should yield me several tickets, it gives me more than one row of the same ticket if that ticket...
3
3508
by: Robin S. | last post by:
I tried to ask this question several days ago, but I didn't explain my application correctly. Basically I want to have one record from table "A" and I want to display, say, 5 records from table "B" which are specified by the one record from table "A"... And all on the same form. I do not want to use a subform. The record fields from table "B" must be displayed in text boxes with the record fields from the single record from table "A". ...
5
2226
by: Robert | last post by:
Hello Accessors I have some reports created in Access that are very good for what they do. However, it seems to me that when you are displaying information you don't need to print out that a printer-friendly report is not the best way to go. So, I tried converting one of my Access reports to an Access form. I selected the continuous view to allow displaying multple records but when I went to define my sorting and grouping there was none...
2
2702
by: Megan | last post by:
hello everybody, i know this is a very long post, but i wanted to provide as much detail as possible. quick overview- i want to create a couple of many to many relationships and am wondering how many relationships to create. i am also trying to figure out what relationships to create.
8
5068
by: Matt | last post by:
Hi all, Thank you for taking the time. I have a database with 45 tables on it. 44 tables are linked to a main table through a one to one relationship. My question is, is there no way i can have a query that will pull a single field from all the tables. In other words i should have 44 fields. when i try to do that same, i get an error message saying "Query is too complex"
1
1263
by: Steve | last post by:
I had a consultant develop a web-page reporting system for me, and last week I sat down and reviewed the undelying code. I have never seen something so complex for a system so simple. The system, basically requires a user to login, and based on their login, generates a list of PDF files that they can click and review. The information required to generate the list is kept in an Access database. The site is an SSL secured site (https), ...
8
2967
by: Steve Jorgensen | last post by:
Mailing List management is a good example of a case where my conundrum arises. Say there is a m-m relationship between parties and groups - anyone can be a member of any combintation of groups. Now, let's say the user wants to be able to send mailings to people who have various combinations of membership and non-membership in those groups. Here's a medium-complex example: (Knitting Group or Macrame Group) and Active Contact and Mailing...
13
1887
by: the other john | last post by:
The trouble currently with 3 tables. I'm excluding non-relevant fields... tbl_users PK_user_ID tbl_developers PK_developer_ID FK_developer_user_ID FK_developer_project_ID
4
1716
scubak1w1
by: scubak1w1 | last post by:
Hello, I have a series of database tables in PostgreSQL that I am getting data from and displaying in the web browser (via PHP, SQL, etc.) How about giving some details of what I am looking to do with a simple set of examples? (if you will forgive the verbosity.) I have groups of employees assigned to just one training group - say 'truck drivers', 'shipping technicians', etc - a one to many
0
10455
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10228
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10173
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9052
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6788
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5441
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5573
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4116
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.