Outputting information from relational databases

Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default 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

  2. Similar Questions and Discussions

    1. 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...
    2. 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?
    3. 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...
    4. 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...
    5. 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...
  3. #2

    Default 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

  4. #3

    Default 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

  5. #4

    Default 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

  6. #5

    Default Re: Outputting information from relational databases

    Nevermind. I got it. Thanks!
    noobie2005 Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139