Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Listing menu choices from a database and then linking them 1

Status
Not open for further replies.

Ratbags21

Programmer
Sep 21, 2005
22
GB
Can anyone help?

I am designing a webpage that has a traditional horizontal menu bar + image that takes up the top quarter of the screen.
When a user chooses a top level category from the horizontal menu, I want a list of choices for that category (say "Tutorials") to pop up on the left under the menu bar. using Coldfusion, I can do this by creating a table and populating it using an SQL query like
"Select Level2MenuChoice from Menus where Level1MenuChoice='Tutorials'". That bits fairly straight forward, however...how do I set each choice (in this list) to link to the right html page?

I'm hoping someone out there has done this before - otherwise I'm doomed to hard code everything!!

thanks a lot
 
If I understand what you are after....

In your database table do you have a column of links and a related column of template paths? Something like...

category name link name path
Tutorials How to brush teeth ../teeth.cfm
Tutorials How to comb hair ../hair.cfm

?

Cheers,

Bluetone
 
Hi Bluetone!

Many thanks for your very prompt reply.
Yes, my database is very much like your example
What I do not know how to do is to activate the URL that is found in the corresponding "Link" field
- I guess there must be some kind of syntax to say
(behind the scenes) "if the link is '.../...comb.html'
switch to that webpage."

Thanks a lot

R21
 
Ok you run your query. I assume each record in your database has a key field (a unique identification). I'll assume that is called "ID".

You then display the list in your popup similar to the following:

<CFOUTPUT query="Recordset">
<A href="SomeTemplateName.cfm?ID=#Recordset.ID#">#Recordset.LinkName#</A>
</CFOUTPUT>

What happens here is the CFOUTPUT displays the LinkNames - and displays them as links. When you click on this link you are directed to a new template (called SomeTemplateName.cfm in this example). However, attached to the URL header is some additional information - what you see after the question mark - <A href="SomeTemplateName.cfm?ID=#Recordset.ID#">

By the way <A href="SomeTemplateName.cfm?ID=#Recordset.ID#">
is all on the same line)

The above needs to be in <FORM> tags and your form method must be set to POST.

Ok - in your second template (the one called SomeTemplateName) you run another query similar to this:

<CFQUERY NAME="Recordset2" DATASOURCE=YourDatasource>
SELECT Whatever
FROM table_Whatever
WHERE ID = '#URL.ID#'
</CFQUERY>

This will then pull the data for that specific record.

So to recap - you display the query data in the popup as a hyperlink. When the user clicks the hyperlink they are sent to a second page but the record ID is sent also.

One the second page you use that record ID to pull the specific record info. Feel free to ask additional questions.

Cheers,

Bluetone
 
Once again, Bluetone, thanks very much for that detailed tip. There's just one thing (my fault, I did not explain the layout in enough detail.) This is what my homepage will look like:
* image *
|Home|Tutorials|Articles|Other|etc|
---------------------------------------------------------

Now, if a user clicks on say the tutorial menu choice
the homepage would now look like this:

* image *
|Home|Tutorials|Articles|Other|etc|
---------------------------------------------------------
Photoshop
Dreamweaver
Illustrator
Coldfusion
MS Office
etc

Next, If a user clicks on the "Coldfusion" choice
we would get, say,

* image *
|Home|Tutorials|Articles|Other|etc|
---------------------------------------------------------
CF tags and how to use them
Passing parameters
Linking to a datasource
etc

Finally, the user clicks a tutorial choice and the relevant webpage pops up in the content area of the web page. By the way, I intend to use table layout rather than
frames, so the top part of the screen will stay static
the left "menu" cell will merely change depending on
which choice is clicked, and the actual content html page
is put into the "content" cell.
Hope that makes sense - sorry its very verbose!

thanks a lot

R21

 
You can place any HTML code you want inside the CFOUTPUT - Div tags for layers, Table tags etc. You can format the output anyway you want. So you should be able to create the menu system you are looking for. You can also use CFIF so that the table or layer is only displayed if the CFOUTPUT contains records:

<CFOUTPUT query="Recordset">
<CFIF Recordset.recordcount GT 0>
(Some HTML Goes Here)
<A href="SomeTemplateName.cfm?ID=#Recordset.ID#">#Recordset.LinkName#</A>
(Maybe Some Additional HTML Here)
</CFIF>
</CFOUTPUT>

Cheers,

Bluetone
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top