Solved

do not know the error

Posted on 2009-05-18
16
197 Views
Last Modified: 2013-12-16
I'm getting "pos" is invalid. I've output the #firstRecord# and #lastRecord# and it shows that

First rec: 1
Last rec: 30

After that is error message.
<cfparam name="url.pageno" default="1">

<cfparam name="url.pageSize" default="30">

<cfset pageSize = max(val(url.pageSize),10)> 

<cfset pageNo = max(val(url.pageNo),1)> 

<CFset index="1">

<cfparam name="form.txtBoxValue" default="">

 

 

<cfset variables.data = arrayNew(1)> 

 

<cfif isDefined("form.txtBoxValue") and len(form.txtBoxValue)>

 

  <cfset allTableNames = "335K,335L,335M,335N, 310A,310B,310C,310D">  

 

 

  <cfset allLardonTableNames = "LAA, LCA, LCB, LCC, LCD, LCJ. LCT">  

 

<!---IWS TABLE--->

  <cfloop index="IWSTable" list="#allTableNames#"> 

    <cfquery name="get_ALL" DATASOURCE="DSN_dbl_IWS">       

     SELECT Doc_No, Remarks, Status, Describe

     FROM #IWStable#

     WHERE Doc_No LIKE <cfqueryparam cfsqltype="cf_sql_varchar" value="%#form.txtBoxValue#%">

    </cfquery>

  

    <cfloop query="get_ALL"> <!--- loop through the results, adding the results to the results array ----->

       <cfset pos = arrayLen(ALL.data) + 1>

       <cfset ALL.data[pos] = structNew()>

       <cfset ALL.data[pos].doc_no = get_ALL.doc_no>    

       <cfset ALL.data[pos].Remarks =get_ALL.Remarks>    

       <cfset ALL.data[pos].Status = get_ALL.Status>    

       <cfset ALL.data[pos].Describe = get_ALL.Describe>    

       <cfset ALL.data[pos].tableName = IWStable>

    </cfloop>

 </cfloop>

 

 

<!---LARDON 2 TABLE--->

    <cfloop index="LardonTable" list="#allLardonTableNames#"> 

    <cfquery name="get_ALL" DATASOURCE="Lardon2">       

     SELECT Doc_No, Remarks, Status, Describe

     FROM #Lardontable#

     WHERE Doc_No LIKE <cfqueryparam cfsqltype="cf_sql_varchar" value="%#form.txtBoxValue#%">

    </cfquery>

  

    <cfloop query="get_ALL"> <!--- loop through the results, adding the results to the results array ----->

       <cfset pos = arrayLen(ALL.data) + 1>

       <cfset ALL.data[pos] = structNew()>

       <cfset ALL.data[pos].doc_no = get_ALL.doc_no>    

       <cfset ALL.data[pos].Remarks =get_ALL.Remarks>    

       <cfset ALL.data[pos].Status = get_ALL.Status>    

       <cfset ALL.data[pos].Describe = get_ALL.Describe>    

       <cfset ALL.data[pos].tableName = Lardontable>

    </cfloop>

 </cfloop>

</CFIF>

 

 

 

 

<meta http-equiv="Contecnt-Type" content="text/html; charset=iso-8859-1">

<style type="text/css"> body {background-color=#A7EF9228bdee; }  .style2{color:#b51111} </style></body> 

 

<table>

 <tr> 

  <td>

  Number of files Generated:</br>

  <cfoutput><b>#arrayLen(All.data)#</cfoutput> 

  </td>

</tr>

</table>

<br> 

 

<cfset numberOfPages = ceiling(arrayLen(All.data) / pageSize)> <!--- numb records divided by page Size = how many pages, round up --->

<cfif pageNo gt numberOfPages> <!--- make sure page is not beyond the number of pages ---->

  <cfset

 pageNo = numberOfPages>

</cfif>

 

<!---- calculate the first record to show ---->

<cfset firstRecord = (pageNo - 1) * pageSize) + 1> 

<cfset lastRecord = min(firstRecord + pageSize - 1, arrayLen(All.data)> 

 

<!--- figure out the prev and next pages ---->

<cfset prevPage = max(1, pageNo - 1)>

<cfset nextPage = min(numberOfPages, pageNo + 1)>

 

<br><br>

 

<table width...> <tr> <th width.....><font...>Search Results:</font></th> <tr> 

<td>S/N</td> 

<td>DOC_NO></td> 

<td>DESCRIPTION</td> 

<td>STATUS</td>

<td>REMARKS</td> </tr> 

 

 <cfoutput>First rec:#firstRecord# Last rec: #lastRecord#</cfoutput>

 

<cfloop index="pos" from="#firstRecord#" to="#lastRecord#">

<cfoutput>

<tr> 

 <td>#pos#</td>

 <td>#All.data[pos].Doc_No#</td>

 <td>#All.data[pos].Remarks#</td>

 <td>#All.data[pos].Status#</td>

 <td>#All.data[pos].Describe#</td>

</tr>

</cfoutput>

</cfloop>

</table>

 

<cfif #All.data.Doc_No# is 0>

<font size="4"> There is no records found!</font>

<cfabort>

</cfif><br>

 

</body></html>

 

<cfif val(prevPage)>

<a href="thisPageName.cfm?page=#prevPage#">Previous Page</a>

</cfif>

<cfif val(nextPage)>

<a href="thisPageName.cfm?page=#nextPage#">Next Page</a>

</cfif> 

 

Open in New Window Select All Accept and Award Points Accept as Solution

Open in new window

5th.jpg
0
Comment
Question by:alexanderax
  • 10
  • 6
16 Comments
 
LVL 52

Expert Comment

by:_agx_
ID: 24418577
>   The value of the attribute query, which is currently "pos" is invalid
> ...
>    <cfloop query="pos" startRow="#firstRecord#" endRow="#lastRecord#">

The "query" value should be the name of one of the queries in your code, like "get_ALL".  "pos" is a counter variable, not the name of query.  
0
 

Author Comment

by:alexanderax
ID: 24418615
hmm.. but that's experts gdemaria gave it to me. As he help me throughout my coding. This pos is like an loop for an array but not for the output of query.

As my requirement shows that i need to query for all the tablenames in order to get the drawing number.
So i created an list of structure to loop through it and output the results of drawing number.
0
 

Author Comment

by:alexanderax
ID: 24418888
Hi _agx_:

Why not you tell me how to do an numbing page by using my codes above? Without changing it, is it possible to do an numbering pages which shows previous page, next page and the numbers in it.

You can change the numbing code but not those code that i have created. Anyone got solution?
0
 

Author Comment

by:alexanderax
ID: 24419504
Hi _agx_:

I got error.. Is like looping all the results rather than showing individual search.. Your "get_All" works but now i'm query for 2 datasource which hae different name.
0
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
ID: 24423626
Hi alexanderax,

Can you post your current code and the results/any error?  

I ask because the original code you posted would not cause that error.  In your original code

      You are using a from / to loop
     <cfloop index="pos" from="#firstRecord#" to="#lastRecord#">

     ... instead of a "query" loop as shown in the error message
      <cfloop query="pos" startRow="#firstRecord#" endRow="#lastRecord#">
 

0
 

Author Comment

by:alexanderax
ID: 24425166
sorry.. Guess i got it mix up. Later i will try it again.. So i just have to change to cfloop index instead of query
0
 
LVL 52

Expert Comment

by:_agx_
ID: 24425985
> So i just have to change to cfloop index instead of query

      Yes, that should do the trick
0
 

Author Comment

by:alexanderax
ID: 24428094
i still cannot get it. Got error
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 52

Expert Comment

by:_agx_
ID: 24430265
Can you post the exact code used and the full error message.
0
 

Author Comment

by:alexanderax
ID: 24434679
Sorry.. I changed it to cfloop index.. It works but cannot show the number of pages and is like the variables is not store in the session structure.  
0
 
LVL 52

Expert Comment

by:_agx_
ID: 24435089
We need more information.  Can you explain what you mean by:

1. "session" structure.  You are not using session variables from what I can see.
2. "cannot show the number of pages" ..   ie  What is happening versus what should be happening?


0
 

Author Comment

by:alexanderax
ID: 24435145
hmm.. ok later in few hours tie i will upload the picture and let you see.. Session structure is one of the experts give it to me
0
 

Author Comment

by:alexanderax
ID: 24435524
Base on the code that i attached, i can see the 'previous' and 'next' text..

Let's say user key in the textvalue of "310" and all the 310 supposing to be the results of the output but on the very first page of the results template, it only shows 100 data but when i press 'next', the page still show the same data but only the number of files generated is different.
<cfparam name="url.pageno" default="1">

<cfparam name="url.pageSize" default="30">

<cfset pageSize = max(val(url.pageSize),10)> 

<cfset pageNo = max(val(url.pageNo),1)> 

<CFset index="1">

<cfparam name="form.txtBoxValue" default="">

 

 

<cfset variables.data = arrayNew(1)> 

 

<cfif isDefined("form.txtBoxValue") and len(form.txtBoxValue)>

 

  <cfset allTableNames = "335K,335L,335M,335N, 310A,310B,310C,310D">  

  <cfset allLardonTableNames = "LAA, LCA, LCB, LCC, LCD, LCJ. LCT">  

 

  <cfloop index="IWSTable" list="#allTableNames#"> 

    <cfquery name="get_IWSdata" DATASOURCE="DSN_dbl_IWS">       

     SELECT Doc_No, Remarks, Status, Describe

     FROM #IWStable#

     WHERE Doc_No LIKE <cfqueryparam cfsqltype="cf_sql_varchar" value="%#form.txtBoxValue#%">

    </cfquery>

  

    <cfloop query="get_IWSdata"> <!--- loop through the results, adding the results to the results array ----->

       <cfset pos = arrayLen(variables.data) + 1>

       <cfset variables.data[pos] = structNew()>

       <cfset variables.data[pos].doc_no = get_IWSdata.doc_no>    

       <cfset variables.data[pos].Remarks =get_IWSdata.Remarks>    

       <cfset variables.data[pos].Status = get_IWSdata.Status>    

       <cfset variables.data[pos].Describe = get_IWSdata.Describe>    

       <cfset variables.data[pos].tableName = IWStable>

    </cfloop>

  </cfloop>

 

  <cfloop index="LardonTable" list="#allLardonTableNames#"> 

    <cfquery name="get_LardonData" DATASOURCE="Lardon2">       

     SELECT Doc_No, Remarks, Status, Describe

     FROM #Lardontable#

     WHERE Doc_No LIKE <cfqueryparam cfsqltype="cf_sql_varchar" value="%#form.txtBoxValue#%">

    </cfquery>

  

    <cfloop query="get_LardonData"> <!--- loop through the results, adding the results to the results array ----->

       <cfset pos = arrayLen(variables.data) + 1>

       <cfset variables.data[pos] = structNew()>

       <cfset variables.data[pos].doc_no = get_LardonData.doc_no>    

       <cfset variables.data[pos].Remarks =get_LardonData.Remarks>    

       <cfset variables.data[pos].Status = get_LardonData.Status>    

       <cfset variables.data[pos].Describe = get_LardonData.Describe>    

       <cfset variables.data[pos].tableName = Lardontable>

    </cfloop>

 </cfloop>

 

 <!--- save the data to a session variable --->

 <cfset session.allData = variables.data>

 

<cfelseif isDefined("session.allData")>

 

  <!--- this is not a search, so load the data back from the session variable --->

  <cfset variables.data = session.allData>

 

</CFIF>

 

 

 

 

<meta http-equiv="Contecnt-Type" content="text/html; charset=iso-8859-1">

<style type="text/css"> body {background-color=#A7EF9228bdee; }  .style2{color:#b51111} </style></body> 

 

<table>

 <tr> 

  <td>

  Number of files Generated:</br>

  <cfoutput><b>#arrayLen(variables.data)#</cfoutput> 

  </td>

</tr>

</table>

<br> 

 

<cfset numberOfPages = ceiling(arrayLen(variables.data) / pageSize)> <!--- numb records divided by page Size = how many pages, round up --->

<cfif pageNo gt numberOfPages> <!--- make sure page is not beyond the number of pages ---->

  <cfset pageNo = numberOfPages>

</cfif>

 

<!---- calculate the first record to show ---->

<cfset firstRecord = (pageNo - 1) * pageSize) + 1> 

<cfset lastRecord = min(firstRecord + pageSize - 1, arrayLen(variables.data)> 

 

<!--- figure out the prev and next pages ---->

<cfset prevPage = max(1, pageNo - 1)>

<cfset nextPage = min(numberOfPages, pageNo + 1)>

 

<br><br>

 

<table width...> <tr> <th width.....><font...>Search Results:</font></th> <tr> 

<td>S/N</td> 

<td>DOC_NO></td> 

<td>DESCRIPTION</td> 

<td>STATUS</td>

<td>REMARKS</td> </tr> 

 

 

<cfoutput>

<cfloop index="pos" from="#firstRecord#" to="#lastRecord#">

<tr> 

 <td>#pos#</td>

 <td>#variables.data[pos].Doc_No#</td>

 <td>#variables.data[pos].Remarks#</td>

 <td>#variables.data[pos].Status#</td>

 <td>#variables.data[pos].Describe#</td>

</tr>

</cfloop>

</cfoutput>

</table>

 

<cfif arrayLen(variables.data) eq 0>

<font size="4"> There is no records found!</font>

<input type="button" name="BackToMain" value="Back to Main Page" onClick="location.href='../drawing search/searchEngineMain.cfm'">

<br>

<cfelse>

<input type="button" name="BackToMain" value="Back to Main Page" onClick="location.href='../drawing search/searchEngineMain.cfm'">

<br>

<cfif val(prevPage)>

<a href="Search_resultsTesting.cfm?page=#prevPage#">Previous Page</a>

</cfif>

<cfif val(nextPage)>

<a href="tSearch_resultsTesting.cfm?page=#nextPage#">Next Page</a>

</cfif> 

 

<cfabort>

</cfif>

</body></html>

Open in new window

0
 

Author Comment

by:alexanderax
ID: 24439100
This is the latest version of my numbering codes. It can show 100 results for every pages. On the first page, it shows 1-100 but when i click on the second page, it shows 301-400 which is suppose to be the last page of the results. Same goes to the 3rd and 4th pages.

How to solve this problem? Show me exactly the code  if i'm missing something or do i need to create an application.cfm?
<cfset structAppend(form, url, false)>

<cfparam name="url.pageno" default="0">

<cfparam name="url.pageSize" default="100">

<cfset pageSize = max(val(url.pageSize),10)> 

<cfset pageNo = max(val(url.pageNo),1)> 

<CFset index="1">

<cfparam name="form.txtBoxValue" default="">

 

<cfset variables.data = arrayNew(1)> 

<cfif isDefined("form.txtBoxValue") and len(form.txtBoxValue)>

 

  <cfset DSN_dbl_IWS_TableNames = "335K,335L,335M,335N, 310A,310B,310C,310D">  

  <cfset Lardon2_TableNames = "LAA, LCA, LCB, LCC, LCD, LCJ. LCT">  

 

  <cfloop index="tblName" list="#variables[form.TableNames & '_TableNames']#"> 

    <cfquery name="get_All" DATASOURCE="DSN_dbl_IWS">       

     SELECT Doc_No, Remarks, Status, Describe

     FROM #tblName#

     WHERE Doc_No LIKE <cfqueryparam cfsqltype="cf_sql_varchar" value="%#form.txtBoxValue#%">

    </cfquery>
 

   <cfquery name="get_All" DATASOURCE="Lardon2">       

     SELECT Doc_No, Remarks, Status, Describe

     FROM #tblName#

     WHERE Doc_No LIKE <cfqueryparam cfsqltype="cf_sql_varchar" value="%#form.txtBoxValue#%">

    </cfquery>
 

    <cfloop query="get_All"> <!--- loop through the results, adding the results to the results array ----->

       <cfset pos = arrayLen(variables.data) + 1>

       <cfset variables.data[pos] = structNew()>

       <cfset variables.data[pos].doc_no = get_All.doc_no>    

       <cfset variables.data[pos].Remarks =get_All.Remarks>    

       <cfset variables.data[pos].Status = get_All.Status>    

       <cfset variables.data[pos].Describe = get_All.Describe>    

       <cfset variables.data[pos].tableName = tblName>

    </cfloop>

  </cfloop>
 

 <cfset session.allData = variables.data>

<cfelseif isDefined("session.allData")>

  <!--- this is not a search, so load the data back from the session variable --->

  <cfset variables.data = session.allData>

</CFIF>
 

<p align="center">

<cfset Result_Per_Page="100">

<cfset Total_Records="#arrayLen(Variables.data)#">

<cfparam name="url.pageno" default="0">

<cfset limit=URL.pageno + Result_Per_Page>

<cfset start_result=URL.pageNo + 1>

<cfoutput>Showing results #start_result#-

<cfif limit GT Total_Records>

#Total_Records#

<cfelse>

#limit#

</cfif>

	of #Total_Records#</cfoutput>

</p>
 

<p align="center">

<cfset URL.pageNo=URL.pageNo + 1>
 

<cfif Total_Results GT Result_Per_Page>

<cfif prevPage = URL.pageNo - Result_Per_Page - 1>

	<cfoutput>

	<a href="Search_Resultstesting.cfm?pageNo=#prevPage#&TableNames=#urlencodedformat(form.TableNames)#&txtBoxValue=#urlencodedformat(form.txtBoxValue)#">Previous</a>

	</cfoutput>

</cfif>
 

	<cfset Total_Pages=ceiling(Total_Records/Result_Per_Page)>

<cfloop index="i" from="1" to="#Total_pages#">

	<cfset j=i-1>
 

	<cfset pageNo_value=j*Result_Per_Page>

<cfif pageNo_value EQ URL.pageNo - 1>

	<cfoutput>#i#</cfoutput>

<cfelse>
 

<cfoutput>

<a href="search_Resultstesting.cfm?pageNo=#pageNo_value#&TableNames=#urlencodedformat(form.TableNames)#&txtBoxValue=#urlencodedformat(form.txtBoxValue)#">#i#</a>

</cfoutput>

</cfif>

</cfloop>
 

<cfif limit LT Total_Records>

<cfset nextPage = URL>pageNo + Result_Per_Page -1>

<cfoutput>

<a href="search_Resultstesting.cfm?pageNo=#nextPage#&TableNames=#urlencodedformat(form.TableNames)#&txtBoxValue=#urlencodedformat(form.txtBoxValue)#">Next

</a>

</cfoutput>

</cfif>

</cfif>

</p>

 

 

<meta http-equiv="Contecnt-Type" content="text/html; charset=iso-8859-1">

<style type="text/css"> body {background-color=#A7EF9228bdee; }  .style2{color:#b51111} </style></body> 

 

<table>

 <tr> 

  <td>

  Number of files Generated:</br>

  <cfoutput><b>#arrayLen(variables.data)#</cfoutput> 

  </td>

</tr>

</table>

<br> 

 

<cfset numberOfPages = ceiling(arrayLen(variables.data) / pageSize)> <!--- numb records divided by page Size = how many pages, round up --->

<cfif pageNo gt numberOfPages> <!--- make sure page is not beyond the number of pages ---->

  <cfset pageNo = numberOfPages>

</cfif>

 

<!---- calculate the first record to show ---->

<cfset firstRecord = (pageNo - 1) * pageSize) + 1> 

<cfset lastRecord = min(firstRecord + pageSize - 1, arrayLen(variables.data)> 

 

<!--- figure out the prev and next pages ---->

<cfset prevPage = max(1, pageNo - 1)>

<cfset nextPage = min(numberOfPages, pageNo + 1)>

 

<br><br>

 

<table width...> <tr> <th width.....><font...>Search Results:</font></th> <tr> 

<td>S/N</td> 

<td>DOC_NO></td> 

<td>DESCRIPTION</td> 

<td>STATUS</td>

<td>REMARKS</td> </tr> 

 

 

<cfoutput>

<cfloop index="pos" from="#firstRecord#" to="#lastRecord#">

<tr> 

 <td>#pos#</td>

 <td>#variables.data[pos].Doc_No#</td>

 <td>#variables.data[pos].Remarks#</td>

 <td>#variables.data[pos].Status#</td>

 <td>#variables.data[pos].Describe#</td>

</tr>

</cfloop>

</cfoutput>

</table>

 

<cfif arrayLen(variables.data) eq 0>

<font size="4"> There is no records found!</font>

<input type="button" name="BackToMain" value="Back to Main Page" onClick="location.href='../drawing search/searchEngineMain.cfm'">

<br>

<cfelse>

<input type="button" name="BackToMain" value="Back to Main Page" onClick="location.href='../drawing search/searchEngineMain.cfm'">

<br>

<cfif val(prevPage)>

<a href="search_Resultstesting.cfm?pageNo=#prevPage#&TableNames=#urlencodedformat(form.TableNames)#&txtBoxValue=#urlencodedformat(form.txtBoxValue)#">Previous Page</a>

</cfif>

<cfif val(nextPage)>

<a href="search_Resultstesting.cfm?pageNo=#nextPage#&TableNames=#urlencodedformat(form.TableNames)#&txtBoxValue=#urlencodedformat(form.txtBoxValue)#">Next Page</a>

</cfif> 

<cfexit>

</cfif>

</body></html>

Open in new window

0
 
LVL 52

Expert Comment

by:_agx_
ID: 24443988
> . It can show 100 results for every pages. On the first page, it shows 1-100 but when i click
> on the second page, it shows 301-400 which is suppose to be the last page of the results.
> Same goes to the 3rd and 4th pages.

Then that is a problem with your pagination code (not the query in this question).  

I tried the logic (with some minor syntax corrections to get the code to compile) and it returned the correct page numbers, first and last record:

test / total records:  400
page 1:  firstRecord = 1, lastRecord = 100
page 2:  firstRecord = 101, lastRecord = 200
page 3:  firstRecord = 201, lastRecord = 300

I am not sure what the problem is. I would ask the expert that provided this code about this problem.
<!--- test with different page numbers --->

<cfset pageNo = 3>

<cfset pageSize = 100>

<cfset numberOfPages = ceiling(arrayLen(variables.data) / pageSize)> <!--- numb records divided by page Size = how many pages, round up --->

<!---- calculate the first record to show ---->

<cfset firstRecord = ((pageNo - 1) * pageSize) + 1> 

<cfset lastRecord = min(firstRecord + pageSize - 1, arrayLen(variables.data))> 

 

<!--- figure out the prev and next pages ---->

<cfset prevPage = max(1, pageNo - 1)>

<cfset nextPage = min(numberOfPages, pageNo + 1)>

Open in new window

0
 

Author Comment

by:alexanderax
ID: 24447107
Can you help me ask? Because my time here is like 12hours difference.. So is kind of hard to contact..
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The purpose of this video is to demonstrate how to insert an Iframe into WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Open Page or Post…
The purpose of this video is to demonstrate how to add AdSense Ads to a WordPress Website, and how to set up WordPress to automatically place Ads in Sidebars. This will be demonstrated using a Windows 8 PC. Log into your AdSense account. : Cli…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now