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

skb73Asked:
Who is Participating?
 
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
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.