Hey guys I have created a userlist page which a drop down form that will allow users to select how many records are display on the page from 20 records to 50 to 100 to 200 but when I try to change to say 100 records I get this error The value "#URL.startrow#" cannot be converted to a number The error occurred in C:\CFusionMX7\wwwroot\Cyberkitten\admin\user_list.cfm: line 12 10 : 11 : 12 : <cfset nNextStartRow = URL.startrow + URL.records_per_page /> 13 : <cfset nPreviousStartRow = URL.startrow - URL.records_per_page /> 14 : <cfif nPreviousStartRow LTE 0> PHP: This is my code for the user_list.cfm page <cfparam name="URL.order_by" default="username" /> <cfparam name="URL.order_by" default="user_id" /> <cfparam name="URL.sort" default="ASC" /> <cfparam name="URL.startrow" default="1" /> <cfparam name="URL.records_per_page" default="20" /> <cfset nNextStartRow = URL.startrow + URL.records_per_page /> <cfset nPreviousStartRow = URL.startrow - URL.records_per_page /> <cfif nPreviousStartRow LTE 0> <cfset nPreviousStartRow = 1 /> </cfif> <cfset nEndRow = URL.startrow + URL.records_per_page - 1/> <cfquery datasource="cyberkitten" name="qUserDetails"> SELECT ck_user.email, ck_user.username, ck_user.user_id FROM ck_user ORDER BY #URL.order_by# #URL.sort# </cfquery> <cfif nEndRow GT qUserDetails.RecordCount> <cfset nEndRow = qUserDetails.RecordCount /> </cfif> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Ck User List</title> <link href="../global.css" rel="stylesheet" type="text/css" media="all"> </head> <body> <cfinclude template = "../adminHeader.cfm" /> <table width="600" border="0" align="center" cellspacing="0"> <cfoutput> <tr> </tr> <tr> <td width="133" bgcolor="dd0067"><strong>ID</strong> <a href="#CGI.SCRIPT_NAME#?order_by=user_id&sort=ASC"><img src="../images/downArrow.gif" border="0"></a> <a href="#CGI.SCRIPT_NAME#?order_by=user_id&sort=DESC"><img src="../images/upArrow.gif" border="0"></a> </td> <td width="193" bgcolor="dd0067"><strong>Username</strong> <a href="#CGI.SCRIPT_NAME#?order_by=username&sort=ASC"><img src="../images/downArrow.gif" border="0"></a> <a href="#CGI.SCRIPT_NAME#?order_by=username&sort=DESC"><img src="../images/upArrow.gif" border="0"></a> </td> <td width="252" bgcolor="dd0067"><strong>Email</strong> <a href="#CGI.SCRIPT_NAME#?order_by=email&sort=ASC"><img src="../images/downArrow.gif" border="0"></a> <a href="#CGI.SCRIPT_NAME#?order_by=email&sort=DESC"><img src="../images/upArrow.gif" border="0"></a> </td> </tr> </cfoutput> <cfoutput query="qUserDetails" maxrows="#URL.records_per_page#" startrow="#URL.startrow#"> <tr> <td bgcolor="de4f92">#qUserDetails.user_id#</td> <td bgcolor="de4f92">#qUserDetails.username#</td> <td bgcolor="de4f92">#qUserDetails.email#</td> </tr> </cfoutput> </table> <br> <table width="200" border="0" align="center" cellspacing="0"> <cfoutput> <tr> <td width="120"> <cfif nPreviousStartRow LT URL.startrow> <a href="#CGI.SCRIPT_NAME#?startrow=#nPreviousStartRow#&records_per_page=#URL.records_per_page#">Previous #URL.records_per_page#</a> </cfif> </td> <td width="120"> <cfif nNextStartRow LT qUserDetails.RecordCount > <a href="#CGI.SCRIPT_NAME#?startrow=#nNextStartRow#&records_per_page=#URL.records_per_page#">Next #URL.records_per_page#</a> </cfif> </td> </tr> </cfoutput> </table> <br> <!-- Records Per Page Form --> <table align="center" width="270"> <tr> <td><form action="#CGI.SCRIPT_NAME#" method="get" name="records"> <strong>Number of Records Per Page</strong> <select name="records_per_page" onChange="document.forms.records.submit();"> <option value="20" <cfif URL.records_per_page EQ 20> selected</cfif>>20</option> <option value="50"<cfif URL.records_per_page EQ 50> selected</cfif>>50</option> <option value="100"<cfif URL.records_per_page EQ 100> selected</cfif>>100</option> <option value="200"<cfif URL.records_per_page EQ 200> selected</cfif>>200</option> </select> <input type="hidden" name="startrow" value="#URL.startrow#" /> <input type="hidden" name="order_by" value="#URL.order_by#" /> <input type="hidden" name="sort" value="#URL.sort#" /> </form> </td> </tr> </table> <!-- End Records Per Page Form --> </body> </html> PHP: I have attached a screen shot of the page. Many Thanks
Try this: <cftry> <cfparam name="URL.startrow" default="1" type="integer" /> <cfcatch type="any"> <cfset URL.startrow = 0> </cfcatch> </cftry> <cftry> <cfparam name="URL.records_per_page" default="20" type="integer" /> <cfcatch type="any"> <cfset Url.Records_Per_Page = 0> </cfcatch> </cftry> What this does is accepts only integers. If the supplied parameter is not an integer (or can't be converted to one), it throws and error. When the error is thrown it caught by CFCATCH which assigns it a value of zero. If the parameter is not supplied it gets its default values. Check to ensure you are ACTUALLY outputting numericals HTH
Hi Thanks for the reply Where do I need to put this code <cftry> <cfparam name="URL.startrow" default="1" type="integer" /> <cfcatch type="any"> <cfset URL.startrow = 0> </cfcatch> </cftry> <cftry> <cfparam name="URL.records_per_page" default="20" type="integer" /> <cfcatch type="any"> <cfset Url.Records_Per_Page = 0> </cfcatch> </cftry> PHP: And what code do I need to remove please I am very new to this
Replace your two cfparam statements with what was sent. Also, ensure that the values of these parameters are actually numbers. - you may need to try outputting them to screen to see what value they are HTH