Friday, September 02, 2005

ColdFusion: Sort With Graphics

I would like to sort data presented in a table (alphanumeric) by pushing small arrow buttons ascending or descending order. How can I accomplish this?

Try this code to get you started:

<cfparam name="url.recordid" default="0">
<cfparam name="url.act" default="">

<cfif url.act is "increase">
<cfquery datasource="mydsn">
Update tbl_records
Set sortid = sortid + 1
Where recorded = #val(url.recordid)#
</cfquery>

<cfelseif url.act is "decrease">
<cfquery datasource="mydsn">
Update tbl_records
Set sortid = sortid - 1
Where recorded = #val(url.recordid)#
</cfquery>
</cfif>

<cfquery name="rs" datasource="mydsn">
Select * from tbl order by sortid
</cfquery>

<table>
<cfloop query="rs">
<tr>
<td>#recordname#</td>
<td><a href="index.cfm?recordid=#recordid#&act=increase">Up</a></td>
<td><a href="index.cfm?recordid=#recordid#&act=decrease">Down</a></td>
</tr>
</cfloop>
</table>

0 Comments:

Post a Comment

<< Home