Topic: Please help with a "Browse Feature"


jov17    -- 02-18-2004 @ 6:53 PM
  I'm trying to execute a simple query against my database to pull all of the "Programs Types" from a table called "Books".  

I'm doing this so that users can browse the books in my books table instead of searching for them.  Everything is working fine with the query and outputing it's results, however in my table there are and will be several books with the same vale for the "program type".  Becuase of this, its displaying the program type several times when I output it.  

How do I ouput the results so that if there are duplicates, it will just show one program type?  

Also, how do I grab the BookID so that I can display them in the next page?

Here is the code:

<h1>Browse to find your book</h1>
<br><br>
<cfquery name="getprograms" datasource="#datasource2#">
SELECT * FROM Books
ORDER BY Program ASC
</cfquery>
<cfoutput query="getprograms">
<a href="search2.cfm?program=#program#">#program#</a><br>
</cfoutput><br><br>

Any help is appreciated.

Thanks




nak    -- 02-18-2004 @ 7:05 PM
  Hello,

You can group your query results. Try:

<cfoutput query="getprograms" group="program">
  
   <a href="search2.cfm?program=#program#">
        #program#
   </a>
   <br>

</cfoutput>


Hope this is what you are asking for.


jov17    -- 02-18-2004 @ 7:14 PM
  Thanks, that worked perfectly, but how do I display every record for that grouped category on the next page?

Thanks again for your help, It's very much appreciated.



nak    -- 02-18-2004 @ 7:19 PM
  Try:

<cfoutput query="getprograms" group="program">
  
   <a href="search2.cfm?program=#program#">
        #program#
   </a>
     <cfoutput>
        #BookTitle# <br>
     </cfoutput>
   <br>
   <br>
</cfoutput>





jov17    -- 02-18-2004 @ 7:37 PM
  when I output the query, it only outputs one of the book titles, not both of them in this case.

See, I'm passing the BookID through the url, well on the search2.cfm page (the next page), it only pulls the bookid for that one book, it needs to pull it for all the books in that category.



jov17    -- 02-18-2004 @ 7:45 PM
  Thanks bro, for all your help, but I figured it out.

I'm not supposed to pass the BookID, I'm supposed to pass the category type in the url, then doanother query on the search2.cfm page.

Thanks for your help though, I wouldn't have figured it out without you!


nak    -- 02-18-2004 @ 7:49 PM
 

This is what I understand. You have a browse page that lists the different 'programs' in your table. If an user clicks on the Programs link, they are directed to search2.cfm.  On this page, the user sees a list of titles that are that 'program' value.

Right?

If this is what you need, try:

<!--- browse.cfm --->

<cfoutput query="getprograms" group="program">
  
   <a href="search2.cfm?program=#program#">
        #program#
   </a>
    
   <br>
   <br>
</cfoutput>


<!--- end browse.cfm --->


<!--- search2.cfm --->
<cfquery name="GetTitles" datasource=#datasource#">
SELECT BookTitle
FROM Books
WHERE Program = #URL.Program#
</cfquery>

<cfoutput query="GetTitles">
  #BookTitle#
</cfoutput>

<!--- end search2.cfm --->

Is this what you need?


jov17    -- 02-18-2004 @ 10:34 PM
  Thanks nak!

Thanks exactly what I needed.  i appreciate all of your help.


EasyCFM.COM ColdFusion Forums : http://archive.easycfm.com/forums
Topic: http://archive.easycfm.com/forums/viewmessages.cfm?Forum=12&Topic=2983