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

sort using URL and Session not working from Page to Page

Status
Not open for further replies.

jedrtd

Programmer
Jul 22, 2001
23
US
here is the code, I have been fooling with this for days, I can do the sort but when you sort and then try to go to page 2 etc, it goes by to the default sort,
This is the detail page, I have it keeping the session var from the summary page.

--->
<cflock scope="session" throwontimeout="no" type="exclusive" timeout="30">
<cfparam name="session.ordreby" default="">
<cfif isdefined("url.orderby")>
<cfset session.orderby = url.orderby>
</cfif>
<cfset request.sort = session.orderby>
</cflock
<!--- Maintain summary filtering variables at session level --->
<!--- Variable carried from the summary page --->
<CFPARAM NAME="session.cust_summary1.UserFilter" TYPE="string" DEFAULT="">
<CFPARAM NAME="session.cust_summary1.DateFrom" TYPE="string" DEFAULT="">
<CFPARAM NAME="session.cust_summary1.DateThru" TYPE="string" DEFAULT="">
<CFPARAM NAME="session.cust_summary1.Rank_By" TYPE="string" DEFAULT="">
<CFPARAM NAME="session.cust_summary1.Rank_Order" TYPE="string" DEFAULT="">
<!--- Variable to do the sorting --->
<CFPARAM NAME="SESSION.recordidin" default="">

<!--- Variable to select Customer from Summary Page --->
<CFPARAM NAME="url.recordidin" default="">
<cflock scope="session" throwontimeout="no" type="exclusive" timeout="30">
<cfparam name="session.ordreby" default="">
<cfif isdefined("url.orderby")>
<cfset session.orderby = url.orderby>
</cfif>
<cfset request.sort = session.orderby>
</cflock

<cfif isdefined("url.orderby")>
<cfset session.orderby = trim(url.orderby)>
<cfset form.rank_by = trim(url.orderby)>
<cfelseif isdefined("form.rank_by")>
<cfset session.orderby = trim(form.rank_by)>
<cfelse>
<cfset session.orderby = "profit">
</cfif>
<cfif Isdefined("url.orderbytype")>
<cfset session.orderbytype= trim(url.orderbytype)>
<cfset form.rank_order=trim(url.orderbytype)>
<cfelseif isdefined("form.rank_order")>
<cfset session.orderbytype = trim(form.rank_order)>
<cfelse>
<cfset session.orderbytype="asc">
</cfif>

<CFIF IsDefined("FORM.UserFilter")>
<CFSET SESSION.summary.UserFilter = FORM.UserFilter>
<CFSET SESSION.summary.DateFrom = FORM.DateFrom>
<CFSET SESSION.summary.DateThru = FORM.DateThru>

</CFIF>


<!--- Set up for Customer Select from Summary Page --->
<cfif isdefined("form.debtor_acct_no")>
<cfset session.recordidin = trim(form.debtor_acct_no)>
<cfelseif isdefined("url.debtor_acct_no")>
<cfset session.recordidin = trim(url.debtor_acct_no)>
</cfif>

<!--- <cfif not isdefined("url.orderbytype")>
<cfset url.orderbytype=session.orderbytype>
</cfif>
<cfif not isdefined("url.orderby")>
<cfset url.orderby=session.orderby>
</cfif> --->
<!--- set return to summary page 0--->
<cfset list_page="customer_summary.cfm">
<!--- Retrieve expense records from database --->
<CFQUERY NAME="Summary" DATASOURCE="Printstreamtest" >
SELECT JOB_NO, BILL_COMPANY, Revenue, COST, Profit, SALESREP, DEBTOR_ACCT_NO,
Margin FROM JOB_SUMMARY WHERE debtor_acct_no='#session.recordidin#' AND Invoice_DATE IS NOT NULL AND PROFIT <> 0
<!--- If the user provided a filter string, --->
<!--- show only matching films and/or expenses --->
<CFIF session.cust_summary1.UserFilter IS NOT "">
AND (BILL_COMPANY LIKE '%#session.cust_summary1.UserFilter#%' OR JOB_NO LIKE '%#session.cust_summary1.UserFilter#%'
OR SALESREP LIKE '%#session.cust_summary1.UserFilter#%' OR DEBTOR_ACCT_NO LIKE '%#session.cust_summary1.UserFilter#%'
OR MARGIN LIKE '%#session.cust_summary1.UserFilter#%')
</CFIF>
<!--- Also filter on From date, if provided --->
<CFIF IsDate(session.cust_summary1.DateFrom)>
AND INVOICE_DATE >= #CreateODBCDate(session.cust_summary1.DateFrom)#
</CFIF>
<!--- Also filter on Through date, if provided --->
<CFIF IsDate(session.cust_summary1.DateThru)>
AND INVOICE_DATE <= #CreateODBCDate(session.cust_summary1.DateThru)#
</CFIF>

ORDER BY #session.orderby# #session.orderbytype#
<!--- ORDER BY Variance ASC --->
</CFQUERY>
<cfquery dbtype="query" name="SummarySum" >
SELECT sum(REVENUE) AS TotalRev, sum(Cost) AS TotalCost, sum(PROFIT) AS TotalProfit, ((sum(Profit)/sum(Revenue))*100) AS TotalMargin FROM Summary
where debtor_acct_no='#session.recordidin#'
</cfquery>
<!--- Number of rows to display per Next/Back page --->
<CFSET RowsPerPage = 20>
<!--- What row to start at? Assume first by default --->
<CFPARAM NAME="URL.StartRow" DEFAULT="1" TYPE="numeric">
<!--- Allow for Show All parameter in the URL --->
<CFPARAM NAME="URL.ShowAll" TYPE="boolean" DEFAULT="No">
<!--- We know the total number of rows from query --->
<CFSET TotalRows = summary.RecordCount>
<!--- Show all on page if ShowAll passed in URL --->
<CFIF URL.ShowAll>
<CFSET RowsPerPage = TotalRows>
</CFIF>
<!--- Last row is 10 rows past the starting row, or --->
<!--- total number of query rows, whichever is less --->
<CFSET EndRow = Min(URL.StartRow + RowsPerPage - 1, TotalRows)>
<!--- Next button goes to 1 past current end row --->
<CFSET StartRowNext = EndRow + 1>
<!--- Back button goes back N rows from start row --->
<CFSET StartRowBack = URL.StartRow - RowsPerPage>

<!--- Page Title --->
<HTML>
<HEAD>
<TITLE>Customer Profit detail</TITLE>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</HEAD>
<SCRIPT LANGUAGE="JavaScript">
<script src="sortable.js"<>/script
<!--
var browser=navigator.appName + " " + navigator.appVersion;
function calendar1()
{
var newWind=window.open('calendar1.cfm','remote','width=350,height=230');
if (newWind.opener == null)
{ newWind.opener = window; }
}
function calendar2()
{
var newWind=window.open('calendar2.cfm','remote','width=350,height=230');
if (newWind.opener == null)
{ newWind.opener = window; }
}
//-->
</SCRIPT>
<BODY background="../aborCost/Images/abrbacklogogreen.jpg" link="#0000FF" vlink="#0000FF" alink="#0000FF">
<CFOUTPUT>
<H2 align="center"><font color="##000099">ABR Services, Inc Details for Sales
and Profit</font></H2>
</CFOUTPUT>
<!--- Simple style sheet for formatting --->
<STYLE>
FORM {font-family:sans-serif;font-size:smaller;}
TH {font-family:sans-serif;font-size:smaller;
backgroundrange;color:white}
TD {font-family:sans-serif;font-size:smaller}
TD.DataA {background:silver;color:black}
TD.DataB {background:lightgrey;color:black}
</STYLE>
<!--- Simple form to allow user to filter results --->
<CFOUTPUT>
<H2 align="center">
<!--- Simple style sheet for formatting --->
<STYLE>
FORM {font-family:sans-serif;font-size:smaller;}
TH {font-family:sans-serif;font-size:smaller;
backgroundrange;color:white}
TD {font-family:sans-serif;font-size:smaller}
TD.DataA {background:silver;color:black}
TD.DataB {background:lightgrey;color:black}
</STYLE>
<!--- Simple form to allow user to filter results --->
</H2>
</CFOUTPUT>
<div align="center"></div>
<CFFORM ACTION="#CGI.SCRIPT_NAME#" METHOD="get" name="myform">
<div align="center"></div>
<table width="80%" border="2" align="center" cellpadding="1" cellspacing="2" bordercolor="#000099" bgcolor="#CCCCCC">
<tr>
<td colspan="2"> <div align="center"><strong><font size="-1">FILTER JOB
LIST WITH SELECTIONS BELOW AND CLICK APPLY:</font></strong></div></td>
</tr>
<tr valign="middle">
<td bordercolor="#CCCCCC"> &nbsp;&nbsp;<strong><b>&nbsp;&nbsp;&nbsp;Rank
By <cfinput name="rank_by" Type="text" Value="#session.orderby#" size="24">
<!---- </b>:</strong> <select name="Rank_By" id="select6">
<option value="Job_No">Job Number</option>
<option value="REVENUE">Revenue</option>
<option value="Cost">Cost</option>
<option value="Margin">Margin</option>
<option value="PROFIT">Profit</option> --->
<cfinput name="rank_order" Type="text" value="#session.orderbytype#" size="24">
<!--- </select> &nbsp;&nbsp;&nbsp;&nbsp;<strong>Order:</strong> <select name="Rank_Order" id="select7">
<option value="ASC">Ascending</option>
<option value="DESC">Descending</option>
</select> ---></td>
<td nowrap bordercolor="#CCCCCC"><b>
<!--- Filter string --->
Filter:</b> <cfinput name="UserFilter" type="Text"
value="#session.cust_summary1.UserFilter#"
size="25"></td>
</tr>
<tr valign="middle">
<td nowrap bordercolor="#CCCCCC">&nbsp; <b>
<!--- From date --->
&nbsp;&nbsp;&nbsp;Dates:</b> From
<cfinput name="DateFrom" type="Text"
value="#session.cust_summary1.DateFrom#"
size="9"
message="Please enter a valid date, or leave it blank."
validate="date"> <a href="javascript:calendar1()"><img src="file:///C|/CFusionMX/ width="18" height="19" border="0"></a>
<!--- Through date --->
Through
<cfinput name="DateThru" type="Text"
value="#session.cust_summary1.DateThru#"
size="9"
message="Please enter a valid date, or leave it blank."
validate="date"> <a href="javascript:calendar2()"><img src="file:///C|/CFusionMX/ width="18" height="19" border="0"></a>
</td>
<td width="20%" nowrap bordercolor="#CCCCCC"> <div align="center">
<!--- Submit button to activate/change/clear filter --->
<input name="Submit"
type="Submit"
value="Apply">
</div></td>
</tr>
</table>
</CFFORM>
<CFFORM ACTION="#CGI.SCRIPT_NAME#" METHOD="post" name="myform">
<table width="100%" border="0" align="center" cellpadding="1" cellspacing="0" class="sortable" id="999">
<!--DWLayoutTable-->
<!--- Row at top of table, above column headers --->
<tr>
<td height="53" colspan="2">
<!--- Message about which rows are being displayed --->
<cfoutput> Displaying <b>#URL.StartRow#</b> to <b>#EndRow#</b> of <b>#TotalRows#</b> Records <a href=#list_page#>[Link
to Profit Summary Page]</a><br>
</cfoutput> </td>
<td colspan="5" align="right" valign="bottom"> <cfif NOT URL.ShowAll>
<!--- Provide Next/Back links --->
<cfinclude template="../Job_Rank/NextNIncludeBackNext.cfm">
</cfif> </td>
</tr>
<!--- Row for column headers --->
<tr>
<th height="48" colspan="2" valign="middle"> <div align="right">Totals For
Selection&nbsp;&nbsp;</div></th>
<th width="176" valign="middle"><!--DWLayoutEmptyCell-->&nbsp;</th>
<th width="200"> <div align="right"><cfoutput>#Dollarformat(SummarySum.TotalRev)#</cfoutput>&nbsp;</div></th>
<th width="200"> <div align="right">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<cfoutput>#Dollarformat(SummarySum.TotalCost)#</cfoutput>&nbsp;</div></th>
<th width="200"> <div align="right"><cfoutput>#Dollarformat(SummarySum.TotalProfit)#</cfoutput>&nbsp;</div></th>
<th width="200"> <div align="left"><cfoutput>
<div align="right">#LSNumberFormat(SummarySum.TotalMargin,',99999999999999.9')# %</div>
</cfoutput></div>
<div align="right"></div></th>
</tr>
<tr>
<th width="155" height="25"><div align="left">Salesrep</div></th>
<th><div align="left"></div>
<div align="left">Customer</div></th>
<th> <div align="left"><A href="customer_profit_detail.cfm?&orderby=job_no<cfif url.orderbytype eq "asc">&OrderByType=Desc </cfif>">Job No</a></div></th>

<th><div align="right">Revenue</div></th>
<th><div align="right">Cost</div></th>
<th><div align="right">Profit&nbsp;</div></th>
<th> <div align="right">Margin</div></th>
</tr>
<!--- For each query row that should be shown now --->
<cfloop query="summary" startrow="#URL.StartRow#" endrow="#EndRow#">
<!--- Use class "DataA" or "DataB" for alternate rows --->
<cfset Class = IIF(summary.CurrentRow MOD 2 EQ 0, "'DataA'", "'DataB'")>
<cfoutput>
<tr valign="baseline">
<td height="24" nowrap class="#Class#"> <div align="justify"> #Summary.SALESREP#</div></td>
<td nowrap class="#Class#"> <div align="justify"> &nbsp;#Summary.DEBTOR_ACCT_NO#&nbsp; #Summary.BILL_COMPANY#</div></td>
<td class="#Class#"> <div align="justify">
<div align="center">
<div align="left"> <a href="../Detail.cfm?recordID=#Summary.JOB_NO#">#Summary.JOB_NO#</a></div>
</div>
</div></td>
<td class="#Class#"> <div align="right"><i>#DollarFormat(Summary.REVENUE)#</i></div></td>
<td class="#Class#"> <div align="right">#DollarFormat(Summary.COST)#</div></td>
<td class="#Class#"> <div align="right">#DollarFormat(Summary.PROFIT)#</div></td>
<td class="#Class#"> <div align="right">#LSNumberFormat(Summary.Margin,',99999999999999.9')# %</div></td>
</tr>
</cfoutput>
</cfloop>
<!--- Row at bottom of table, after rows of data --->
<tr>
<td height="70" colspan="5"> <cfif NOT URL.ShowAll AND TotalRows GT RowsPerPage>
<!--- Shortcut links for "Pages" of search results --->
Page
<cfinclude template="../Job_Rank/NextNIncludePageLinks.cfm">

<!--- Show All link --->
<cfoutput> <a href="#CGI.SCRIPT_NAME#?&ShowAll=Yes">Show
All</a> </cfoutput> </cfif>
<!--- <CFIF NOT URL.ShowAll>
<!--- Provide Next/Back links --->
<cfinclude template="../Job_Rank/NextNIncludeBackNext.cfm"> </td>
--->
<td align="right">&nbsp;</td>
<td align="right">&nbsp;</td>
</tr>
<tr>
<td height="3"></td>
<td width="537"></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
<div align="center"><strong><B>&nbsp;&nbsp;&nbsp;&nbsp;</B></strong> &nbsp;&nbsp;&nbsp;&nbsp;<strong>
</strong> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</div>
</CFFORM>
</BODY>
</HTML>
 
Maybe this faq will help point you in the right direction. faq232-5680

Beware of programmers who carry screwdrivers.
 
I copied to my code, but when I click the link nothing is happening. I have not used script much where does it go in the code
 
hold on now...
the faq was ment as a guide, not a solution. The FAQ uses the same principle with sessions and url variables. that's why i posted it. It actualy never goes to a second page. it just links to its self.

Beware of programmers who carry screwdrivers.
 
The only problem I was having was that when you tried to use the next, or goto a page it would go back to the default setting not hold the sort setting(URL). The linking on the header is loading the same page, but with the script it load but does not change the sort order, but will not load again. I put the CFScript before the cfquery and after the default were set.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top