Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 279
  • Last Modified:

Add Hyperlink to Query Data

I have this Query bringing back id, desc from database to be displayed on page. How do I add hyperlink to ID so that when the user clicks on the ID .. it takes him to another page based on ID

0
skb73
Asked:
skb73
  • 3
  • 2
1 Solution
 
duncancummingCommented:

page1:
<cfquery name="getData" datasource="dsn">
	SELECT ID, Desc
	FROM yourTable
</cfquery>
 
<cfoutput query="getData">
	<a href="page2.cfm?ID=#getData.ID#">#Left(getData.Desc, 50)#</a><br>
</cfoutput>
 
 
 
page2:
<cfparam name="URL.ID" default="">
 
<cfif NOT Len(URL.ID) OR NOT IsNumeric(URL.ID)>
<!--- something not right --->
	<cflocation url="page1.cfm">
</cfif>
 
<cfquery name="getData" datasource="dsn">
	SELECT ID, Desc
	FROM yourTable
	WHERE ID = #URL.ID#
</cfquery>
 
<cfoutput query="getData">
	#getData.Desc#
</cfoutput>

Open in new window

0
 
_agx_Commented:
skb73,

> WHERE ID = #URL.ID#

(No points please) just a minor comment - Experts tend to omit cfqueryparam in examples to make examples easier to understand.  I do it myself sometimes because cfqueryparam is a bit wordy :) But you should use cfqueryparam instead of using the variables directly.  Example:

<!--- the cfsqltype will vary depending on the data type of your column --->
WHERE ID = <cfqueryparam value="#URL.ID#" cfsqltype="cf_sql_integer">

0
 
skb73Author Commented:
when I reach page2.cfm .. this ID should be part of  list .. how I do that?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
duncancummingCommented:
Can you be  more specific about what you're trying to do?
0
 
skb73Author Commented:
On Page1.cfm .. I have this query
seletc id, process_name, enabled from table1 , the result set  is displayed and ids are hyperlink to page2.
when the ID on page one is clicked.. it  should go to page2 and the process_name for the id should be selected on page 2 in the drop down list..

page 2 displays a List with process names .. for eg.,
select process_name from table2.
0
 
duncancummingCommented:
ok.  page2 should have the same query as page1.  On your page, for your select box, something like:

<select name="whatever">
<cfoutput query="getData">
<cfif getData.ID EQ URL.ID>
<!--- our selected process --->
<option value="#getData.ID#" selected>#getData.process_name#</option>
<cfelse>
<option value="#getData.ID#">#getData.process_name#</option>
</cfif>
</cfoutput>
</select>
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now