Ask a Question related to Coldfusion Database Access, Design and Development.
-
noobie2005 #1
Outputting information from relational databases
Hello,
This is the issue at hand, I have a relational database. Two of the tables are
in a relationship, I have a query that allows a person to search by students
and display all there service hours and the where they participated. Now,
here's where I'm having the problem. I want to search backwards, by searching
the service and getting all the students that participated in that event. I get
output, but only 1 record, and there are about 200+. I've attached the code,
maybe I did something wrong? Help is appreciated. Thank you in advance.
<cfquery name="qrecords" datasource="">
SELECT *
FROM HoursLog
WHERE Service = '#form.Service#'
</cfquery>
<cfquery name="qstudents" datasource="">
SELECT *
FROM Students
WHERE StudentID = '#qrecords.StudentID#'
</cfquery>
<tr>
<td colspan="2" height="100%">
<h2>Search Students</h2>
Below is a list of Students from your search of
"<cfoutput><strong>#form.Service#</strong></cfoutput>":
<br><br>
<cfif #qrecords.recordcount# NEQ 0>
<cftable query = "qstudents" startRow = "1" colheaders colSpacing = "6"
HTMLTable border="1" headerlines="2">
<!--- each cfcol tag sets width of a column in table, and specifies header
information and text/CFML with which to fill cell --->
<cfcol header = "<c>Active?</c>"
align = "Left"
width = 2
text = "#Active#">
<cfcol header = "<c>Student ID</c>"
align = "Left"
width = 2
text = "<a
href=displaystudent.cfm?StudentID=#StudentID#>#Stu dentID#</a>">
<cfcol header = "<c>Last Name</c>"
align = "Left"
width = 15
text = "#LastName#">
<cfcol header = "<c>First Name</c>"
align = "Center"
width = 15
text = "#FirstName#">
<cfcol header = "<c>Country</c>"
align = "Center"
width = 15
text = "#Country#">
<cfcol header = "<c>Major</c>"
align = "Center"
width = 15
text = "#Major#">
<cfcol header = "<c>CS Hours</c>"
align = "Center"
width = 15
text = "#CSHours#">
</cftable>
<cfelse>
Sorry, your search for "<cfoutput><strong>#form.Service#</strong></cfoutput>"
did not return any results. Please <a href="index.cfm">search again</a>.
<br><br><br>
</cfif>
</td>
</tr>
noobie2005 Guest
-
SQL select information from two databases
Hi I'm working on a ColdFusion project that has more than 8 diffrent data sources. I'm trying to select the information inside a table called... -
How do I query third-party public information databases.
I read an article on Wired.com about "Zabasearch" and wanted to know how are they writing queries that go to the courts, dmv, etc? -
FileMaker Pro 6 and relational databases
I'm used to using SQL for databases, and I really can't get my head around the way Filemaker does it (it took me long enough to come to the... -
Just how relational should one be??
I have had a very interesting and enriching ride over the past two months taking my database of two files and doing with it what I should have done... -
Federated Databases, joins across databases etc
Greetings, I want to do a join between 2 tables on 2 different db2 databases on the same server. I assume that I have to use federated databases. I... -
paross1 #2
Re: Outputting information from relational databases
You really only need one query.
Phil
<cfquery name="qstudents" datasource="">
SELECT *
FROM Students s
WHERE EXISTS
(SELECT 1
FROM HoursLog h
WHERE h.Service = '#form.Service#'
AND h.StudentID = s.StudentID
</cfquery>
paross1 Guest
-
paross1 #3
Re: Outputting information from relational databases
....or, if you need data from both tables, you might try somethin like this.
Phil
<cfquery name="qstudents" datasource="">
SELECT *
FROM Students s
INNER JOIN HoursLog h ON h.StudentID = s.StudentID
WHERE h.Service = '#form.Service#'
</cfquery>
paross1 Guest
-
noobie2005 #4
Re: Outputting information from relational databases
Hey Thanks,
It working now, but it repeats. I tried doing a DISTINCT * but that did'nt work. Do I specifiy the DISTINCT attrib on the StudentID?
noobie2005 Guest
-
noobie2005 #5
Re: Outputting information from relational databases
Nevermind. I got it. Thanks!
noobie2005 Guest



Reply With Quote

