Here's the setup...
I am working on my church's web site and we have an online directory of
members. I have a page that displays 10 families at a time with their listed
address, phone, etc. You then drill down to see the members of any given
family. On the page that displays the families and their addresses, I have the
alphabet in hopes of allowing the user to view those families, whose last name
starts with that selected letter. There is a code sample of the link setup
below.
I have also created another query that will use the data in the query string
to sort the families. It is also shown in a code sample below.
Can you help me out to see how to integrate the two together, or...better
yet...show me an even easier/better solution for what I am trying to
accomplish? Thanks, in advance.
*****LINKS*****
<table border="0" cellpadding="3" cellspacing="0" width="100%" align="center">
<tr>
<td align="center"><font size="-2"><a
href="memberDirectory.cfm?sortBy=A">A</a></font></td>
<td align="center"><font size="-2"><a
href="memberDirectory.cfm?sortBy=B">B</a></font></td>
<td align="center"><font size="-2"><a
href="memberDirectory.cfm?sortBy=C">C</a></font></td>
...
*****QUERY*****
<cfquery name="rs_familiesSortByName" datasource="farragutChurch">
SELECT *
FROM tbl_families
WHERE lastName LIKE '#URL.sortBy#%'
ORDER BY lastName ASC
</cfquery>
too make the links, can use a loop :
<cfoutput>
<cfloop from="65" to="90" index="c">
memberDirectory.cfm?sortBy=#chr(c)# <br>
</cfloop>
</cfoutput>
not sure what the other of the two questions you mentioned were :)
Looch - 08 Oct 2004 04:10 GMT
Thanks for your input, but I already have the links built. I may change it
around like you said, just so I can learn the code a little better, though.
All that I am looking to do is to view a list of families by last name. For
instance, if somebody were to click the 'S' link, then you would see the the
Smith's, Summer's, and Swanson's familiy information. I wouldn't want to see
any other family's info other than those whose last name begins with the letter
selected.
The query that I have listed in my last post will take a letter and run it
against the database to give me the data that I want. What I need to know is
how to get my page to run that query and get that data output when somebody
clicks a link (i.e. the 'S') to get the familiy's whose last name begins with
that letter.
I hope that I have explained this a little better. Any help would be
appreciated.
NateNielsen - 08 Oct 2004 05:12 GMT
inside memberDirectory.cfm, as long as the query you have looks like :
SELECT *FROM tbl_familiesWHERE lastName LIKE '#URL.sortBy#%'ORDER BY lastName
ASC
(which is what it looks like you have) it should work just fine. are you
getting an error or no results ?
Looch - 08 Oct 2004 13:44 GMT
The problem that I am having is not knowing how to integrate that query and
it's results into the letters that should call the query once clicked. You
see, when the page is called initially it does a query called "rs_query1",
which looks like this...
SELECT *
FROM tbl_families
ORDER BY lastName ASC
It just pulls all of the families and then shows 10 at a time on the page.
The user has the option to scroll through the names 10 at a time or to go to
the last set of names and then back to the first set. On the page I am only
calling the data from this query something like this...
rs_query1.lastName
rs_query1.Address
...
Maybe I need to use the other query to get the data from. My problem might be
that I am always pulling the data onto the page from the query above. How
should I go about fixing this so that It will pull all of the families when the
page is intially loaded and then sort by a certain letter when that letter is
clicked?
Here's a little more info that might be of help...
On the same page, I also have the other query that you wrote out in your last
post (there are 2 very similar queries on the page). All that I want to have
happen is to click the 'S' link and it will get all of the families from the
database whose last name starts with an 'S'. I hope that I am making this
clear. I might be able to chuck some junk data out there and give you a screen
shot as to what it is doing, but it will take a while. I just don't want to
put other people's personal info out there for anyone to see. Let me know if
this helps and if you think that you can help with a solution. I would REALLY
appreciate it.
Telix - 08 Oct 2004 14:02 GMT
hiya
if you are calling the same page or even the same query, maybe it goes
something like this...
where ever your query is try to incorporate your sort by variable into the
query. That is the easiest way to do it....
*****QUERY*****
<cfquery name="rs_familiesSortByName" datasource="farragutChurch">
SELECT *
FROM tbl_families
<cfif isDefined("sortBy")>
WHERE lastName LIKE '#URL.sortBy#%'
</cfif>
ORDER BY lastName ASC
</cfquery>
hope that helps you out a bit....There are of course a lot more ways but I
find this the easiest.
Looch - 08 Oct 2004 14:11 GMT
Man!...I think that may work. I can't believe that I was so blind to such a
simple solution. Thanks for pointing it out. I'll try it out when I get the
chance to work on the site again, and post back here whether or not it worked.
Thanks, Telix!
Looch - 29 Oct 2004 20:26 GMT
You would think that would work, Telix, and to some extent it does. However,
when the page loads initially, no data is output to the page. I don't know if
it is skipping over the query because "sortBy" does not exist or
what, but there is no data being output. I copied it just as you had written
it out in your last post. What gives? It seems like it should work and skip
over the <cfif> tags when "sortBy" is not defined. Also, when
I take the <cfif> statement out, it works like it should on the initial
page load, but then I am back at stage one and not knowing how to sort the data
by last name. Any other thoughts on how to resolve this? Thanks!
Looch - 29 Oct 2004 21:04 GMT
One more thing...the variable "sortBy" is getting set to 1 when the
page loads initially. This is probably why no data is being output. How can I
make sure that the variable "sortBy" will not be defined on the
initial page load? Would it be dumb to have the <cfif> in the SQL
statement check to see if sortBy is equal to 1 instead of just checking to see
if it is defined. I guess it is getting defined somewhere, but I am not sure
where. Any thoughts? Thanks!
Looch - 29 Oct 2004 21:52 GMT
Well, I may have just figured it out. I changed the <cfif> tag to read
like this... <cfif sortBy is not 1> that way if it is not 1 then it
will add the WHERE clause to the SQL. If it is 1 (which is what happens on the
initial page load for some reason) then it will not add the WHERE clause and
output all of the data. This has cleared up the situation. I'm sure that
there are other ways that this could be done, but this works fine for me. Post
your solutions here if you can think of any other way to do this. Otherwise,
this is the solution to the initial problem. Thanks for all the insight,
everyone!
Looch - 08 Oct 2004 04:11 GMT
Thanks for your input, but I already have the links built. I may change it
around like you said, just so I can learn the code a little better, though.
All that I am looking to do is to view a list of families by last name. For
instance, if somebody were to click the 'S' link, then you would see the the
Smith's, Summer's, and Swanson's familiy information. I wouldn't want to see
any other family's info other than those whose last name begins with the letter
selected.
The query that I have listed in my last post will take a letter and run it
against the database to give me the data that I want. What I need to know is
how to get my page to run that query and get that data output when somebody
clicks a link (i.e. the 'S') to get the familiy's whose last name begins with
that letter.
I hope that I have explained this a little better. Any help would be
appreciated.