Relating tables in an output

Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.

  1. #1

    Default Relating tables in an output

    Hello all,
    Hopefully I can explain this well enough to undersand what I am trying to do.
    I have a page that displays all of our glossary terms in alphabetical order
    grouped by the first letter. Above the list of terms I have a table with all 26
    letters with links to an anchor that will take you to the selected letter.

    What I would like to do is only have a link to the anchor if there is a
    related anchor further on the page.
    Here are the two tables that I am using:
    Alphabet Table: alpha_id (primary key)field , letter field
    Glossary Table: term_id (primary key)field, name field, meaning field,
    first_character field

    If I just use the one query that gets all the information from the glossary
    table I can't seem to figure out a way to show letters that are not defined in
    the first_character field. If I use the alphabet table to show all the letters
    and just use the glossary table to set the links I get a link on all the
    letters, letters that don't have an anchor to jump to obviously don't go
    anywhere.
    What I am looking to try to do with an if/else statement is, Put the link on
    the letter if there is a corresponding letter in the glossary table if not just
    show the letter in my specified color without a link.

    I hope this all makes sense and thank you inadvance for your help.
    jmoshier



    <!---select all the glossary terms to be displayed on the page--->
    <cfquery name="getGlossary" datasource="erinc_docs">
    SELECT * FROM glossary ORDER BY first_character, name
    </cfquery>

    <!---get letters for links at top of page--->
    <cfquery name="getLetters" datasource="erinc_docs">
    SELECT * FROM alphabet ORDER BY letter
    </cfquery>

    Here is the code that dislays all the letters in a table:
    <cfoutput query="getLetters">
    <td width="11" bgcolor="##FFFFFF">
    <div align="center"><a href="###letter#">#letter#</a></div>
    </td>
    </cfoutput>

    Here is the code to display the terms:
    <table>
    <cfoutput query="getGlossary" group="first_character">
    <tr bgcolor="##f7f7f7">
    <td valign="top" bgcolor="##ffffff"><div
    align="center"><strong>#first_character#</strong><a
    name="#first_character#"></a></div></td>
    <td bgcolor="##ffffff">
    <table width="100%" cellpadding="0" cellspacing="2"
    border="0">
    <cfoutput>
    <tr>
    <td
    bgcolor="##ffffff"><strong>#getGlossary.name#</strong> -
    #getGlossary.meaning#</td>
    </tr>
    <tr>
    <td bgcolor="##ffffff"><img
    src="../_common/images/spacer_grey.gif" width="100%" height="1"></td>
    </tr>
    </cfoutput>
    <tr>
    <td align="right" bgcolor="##ffffff"><a
    href="##top">Top of Page</a></td>
    </tr>
    </table></td>
    </tr>
    </cfoutput>
    </table>

    jmoshier Guest

  2. Similar Questions and Discussions

    1. ClassCastException relating to cfloop and Structs?
      I am upgrading a piece of code from CF5 to CF7, and it keeps getting ClassCastExceptions. This is the only real problem I've encountered in the...
    2. Couple of questions relating to programming
      Hi, I am a video game programmer who is used to programming in C++ inside Visual Studio.NET 2003. I need to code a fairly complicated web site...
    3. relating record to picture
      i have an interface where people can sign up and provide details, for an online ystsem for people to meet others, its a prototype for my...
    4. relating iostat output to mount points
      Friends, I see following headings (amongst others) when I run iostat: sd0 sd6 sd15 sd21 How do I relate these disks with...
    5. questions relating to dropdown list
      hi, i am making a grammar exercise for children where they will have to fill in the blanks in a paragraph with the appropriate word. i have...
  3. #2

    Default Re: Relating tables in an output

    Try the something like the following...

    <!-- *************************** -->
    <!-- Insert after the GetLetters Query -->
    <!-- *************************** -->

    <!-- create index tracking structure to determine if index item has
    information -->
    <cfset alphabetArray = structnew()>

    <!-- Mark all items having no link -->
    <cfloop query = "GetLetters">
    <cfset alphabetArray[letter] = "-">
    </cfloop>

    <!-- Determine index items with links -->
    <cfquery name="getIndex" dbtype="query">
    SELECT DISTINCT first_character FROM GetGlossary ORDER BY first_character
    </cfquery>
    <cfoutput query="getIndex">
    <cfset alphabetArray [#ucase(first_character)#] = first_character>
    </cfoutput>

    <!-- output the index, needs to be modified to get output in desired
    format -->
    <cfoutput>
    <cfloop query = "GetLetters">
    <cfif #alphabetArray[letter]# IS NOT "-">
    &nbsp;<a href="###alphabetArray[letter]#">#letter#</a>&nbsp;
    <cfelse>
    &nbsp;#letter#&nbsp;
    </cfif>
    </cfloop>
    </cfoutput>

    Brian

    "jmoshier" <webforumsuser@macromedia.com> wrote in message
    news:d0q4vl$koh$1@forums.macromedia.com...
    > Hello all,
    > Hopefully I can explain this well enough to undersand what I am trying to
    > do.
    > I have a page that displays all of our glossary terms in alphabetical
    > order
    > grouped by the first letter. Above the list of terms I have a table with
    > all 26
    > letters with links to an anchor that will take you to the selected letter.
    >
    > What I would like to do is only have a link to the anchor if there is a
    > related anchor further on the page.
    > Here are the two tables that I am using:
    > Alphabet Table: alpha_id (primary key)field , letter field
    > Glossary Table: term_id (primary key)field, name field, meaning field,
    > first_character field
    >
    > If I just use the one query that gets all the information from the
    > glossary
    > table I can't seem to figure out a way to show letters that are not
    > defined in
    > the first_character field. If I use the alphabet table to show all the
    > letters
    > and just use the glossary table to set the links I get a link on all the
    > letters, letters that don't have an anchor to jump to obviously don't go
    > anywhere.
    > What I am looking to try to do with an if/else statement is, Put the link
    > on
    > the letter if there is a corresponding letter in the glossary table if not
    > just
    > show the letter in my specified color without a link.
    >
    > I hope this all makes sense and thank you inadvance for your help.
    > jmoshier
    >
    >
    >
    > <!---select all the glossary terms to be displayed on the page--->
    > <cfquery name="getGlossary" datasource="erinc_docs">
    > SELECT * FROM glossary ORDER BY first_character, name
    > </cfquery>
    >
    > <!---get letters for links at top of page--->
    > <cfquery name="getLetters" datasource="erinc_docs">
    > SELECT * FROM alphabet ORDER BY letter
    > </cfquery>
    >
    > Here is the code that dislays all the letters in a table:
    > <cfoutput query="getLetters">
    > <td width="11" bgcolor="##FFFFFF">
    > <div align="center"><a href="###letter#">#letter#</a></div>
    > </td>
    > </cfoutput>
    >
    > Here is the code to display the terms:
    > <table>
    > <cfoutput query="getGlossary" group="first_character">
    > <tr bgcolor="##f7f7f7">
    > <td valign="top" bgcolor="##ffffff"><div
    > align="center"><strong>#first_character#</strong><a
    > name="#first_character#"></a></div></td>
    > <td bgcolor="##ffffff">
    > <table width="100%" cellpadding="0" cellspacing="2"
    > border="0">
    > <cfoutput>
    > <tr>
    > <td
    > bgcolor="##ffffff"><strong>#getGlossary.name#</strong> -
    > #getGlossary.meaning#</td>
    > </tr>
    > <tr>
    > <td bgcolor="##ffffff"><img
    > src="../_common/images/spacer_grey.gif" width="100%" height="1"></td>
    > </tr>
    > </cfoutput>
    > <tr>
    > <td align="right" bgcolor="##ffffff"><a
    > href="##top">Top of Page</a></td>
    > </tr>
    > </table></td>
    > </tr>
    > </cfoutput>
    > </table>
    >

    Guest

  4. #3

    Default Re: Relating tables in an output

    If I understand you correctly, very easy. If I miss the boat, let me know and
    I will fix. After you run the glossary query, creat a list of
    first_character(s). <!---select all the glossary terms to be displayed on the
    page---> <cfquery name='getGlossary' datasource='erinc_docs'> SELECT * FROM
    glossary ORDER BY first_character, name </cfquery> <cfset temp =
    Valuelist(getGlossary.first_character)> Then simply only query letters in the
    list. <!---get letters for links at top of page---> <cfquery name='getLetters'
    datasource='erinc_docs'> SELECT * FROM alphabet ORDER BY letter Where Letter
    IN(#temp# ) </cfquery> No you only have result letters that are in the
    clossary result set. Allen

    CriticalIM Guest

  5. #4

    Default Re: Relating tables in an output

    Allen,
    This is close but if I am understanding your code correctly. The getLetters
    query will only show letters that are in both querys. I want to show all 26
    letters and only have links on the letters that are in the getGlossary query.

    Thanks
    Jennifer

    jmoshier Guest

  6. #5

    Default Re: Relating tables in an output

    you really don't need a seperate column to store 'firstcharacter'. you can
    just do a left(name, 1) AS firstCharcter in your SQL. try the following:
    <cfquery name='getGlossray' datasource='erinc_docs'> SELECT
    left(name, 1) AS firstCharacter, name FROM glossary
    ORDER BY left(name, 1) AS firstCharacter, name </cfquery>
    <cfset alphaList = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y ,z' />
    <cfset glossaryAlphaList = valueList(getGlossary, firstCharacter) />
    <cfoutput> <cfloop list='#alphaList#' index='alpha'> <cfif
    listContains(glossary, alpha)> <a href='###alpha#'>#alpha#</a>
    <cfelse> #alpha# </cfif> </cfloop>
    </cfoutput> *disclaimer: not tested :D

    [CJ] 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