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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Re-order sequence

Status
Not open for further replies.

AlwaysWilling

Programmer
Dec 29, 2005
51
US
Hi all. I query the database and put the elements in a select box in a sequence order based on the sequenceid. The user can sort the sequence any way they want.

EX:
original sequence
1 - Me
2 - You
3 - Her
4 - Him

new sequence
1 - You
2 - Her
3 - Me
4 - Him

How can I do something like that?
 
Have a column in the table called something like "sortorder" and use it to let the user assign the desired sort order.


Hope This Helps!

ECAR
ECAR Technologies

"My work is a game, a very serious game." - M.C. Escher
 
Ok, I managed to get this far. I created a list of my old set of sequence's and then created a list of my new set of serquences, how can i compare the two and reorder?

I am passing the MyTable_ID (PK) and the Sequence fields. I want to know compare the two list and reorder based on the Sequence values.

This is my code:
Code:
<cfquery name="a" datasource="#DS#">
	SELECT * from myTable WHERE Prod_ID = 1
</cfquery>

<cfoutput query="a">
	<cfset oldList = "#a.myTable_ID#| #a.Sequence#:">
	#oldList#
</cfoutput>
<br>
<cfif isdefined("FORM.Submit")>
	<cfloop index="x" list="#FORM.order#" delimiters=",">
		<cfset newList = "#x#">
		<cfoutput>#newList#</cfoutput>
	</cfloop>
</cfif>

<html>
<head>
	<script language="JavaScript" src="sort.js"></script>
</head>

<body>
	<cfoutput>
			<form method="post" action="c.cfm" onSubmit="selectall('order');">
				<select name="order" size="15" multiple="multiple" id="order" onmousewheel="mousewheel(this);">
					<cfif isdefined("FORM.Submit")>
						<cfloop index="x" list="#form.order#" delimiters=",">
							<option value="#x#">#x#</option>
						</cfloop>
					<cfelse>
						<cfloop query="a">
							<option value="#myTable_ID#| #Sequence#:">#First_Name# #Last_Name#</option>
						</cfloop>
					</cfif>				
				</select>
				
				<input type="submit" name="Submit" value="Submit">
			</form>
			
			<input type="button" value="Up" onClick="up('order');" title="Up" />
			<input type="button" value="Down" onClick="down('order');" title="Down" />		
	</cfoutput>
</body>
</html>

[b]
JS Sorter code is from: [URL unfurl="true"]http://www.babailiica.com/js/sorter/sort.js[/URL][/b]
 
I played with the code and now have this version:

I still have an oldList and a newList, but still can't figure out how to re-order the items.

Anyone?

Code:
<cfquery name="a" datasource="#DS#">
    SELECT * from myTable WHERE Prod_ID = 1
</cfquery>

<cfset oldList = valuelist(a.myTable_ID,",")>
<cfoutput>oldList = #oldList#</cfoutput>

<br><br>

<cfif isdefined("FORM.Submit")>
<cfoutput>
	<cfloop index="x" list="#FORM.order#" delimiters="|">
		<cfset newList = "#x#">
		<cfset er = replace(newList,",","<br>","ALL")>
		#er#
		<br><br>
		
		<cfloop index="ad" from="1" to="#listlen(newList)#">
			<cfset qsa = "#ad#,">
			<cfset er2 = replace(qsa,",","<br>","ALL")>
			#er2#
			<br><br>
		</cfloop>
		<br><br>
	</cfloop>
</cfoutput>
</cfif>

<html>
<head>
	<script language="JavaScript" src="[URL unfurl="true"]http://www.babailiica.com/js/sorter/sort.js"></script>[/URL]
</head>

<body>
	<cfoutput>
			<form method="post" action="c.cfm" onSubmit="selectall('order');">
				<select name="order" size="15" multiple="multiple" id="order" onmousewheel="mousewheel(this);">
					<cfif isdefined("FORM.Submit")>
						<cfloop index="x" list="#form.order#">
							<option value="#x#">#x#</option>
						</cfloop>
					<cfelse>
						<cfloop query="a">
							<option value="#myTable_ID#">#First_Name# #Last_Name#</option>
						</cfloop>
					</cfif>				
				</select>
				
				<input type="submit" name="Submit" value="Submit to me">
			</form>
			
			<input type="button" value="Up" onClick="up('order');" title="Up" />
			<input type="button" value="Down" onClick="down('order');" title="Down" />		
	</cfoutput>
</body>
</html>
 
Hi imstillatwork, thanks for that, I actually got it to work the way I wanted, it was just a matter of looping the results and redisplaying. I am not that good with loops logic.

But I did look at your code and all others on your site, and they are very good. I liked them and now bookmarked you! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top