Adobe Dreamweaver Forums



Last 10 THreads :         Event listener (Last Post : lammspillning - Replies : 0 - Views : 1 )           »          Adding database RDS Login Dreamweaver 8 Coldfusion 8 (Last Post : Daverms - Replies : 3 - Views : 4 )           »          Trouble with SQL Query Tool on Leopard (Last Post : pdenlinger - Replies : 2 - Views : 3 )           »          set width of adv. datagrid according to image width. (Last Post : Devsachin - Replies : 0 - Views : 1 )           »          Dreamweaver cs4 (Last Post : Murray *ACE* - Replies : 9 - Views : 10 )           »          Centering a site using layers in browser window (Last Post : Murray *ACE* - Replies : 3 - Views : 4 )           »          Beginner help - PUT confusion (Last Post : Murray *ACE* - Replies : 7 - Views : 8 )           »          URL Fragments and States (Last Post : Broarlimavola - Replies : 13 - Views : 62 )           »          Files and folders becoming read-only (Last Post : Daverms - Replies : 1 - Views : 2 )           »          Downloading from Flash (Last Post : davey darch - Replies : 0 - Views : 1 )           »         


Home Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
User Info Statistics
Go Back   Adobe Dreamweaver Forums > Other Macromedia/Adobe Products > Cold Fusion
 
Tags:



Reply
  #1 (permalink)  
Old 10-07-2008, 05:30 PM
steve grosz
 
Posts: n/a
Diggs:
Default Array and CFC question

Hi!

Ok, here's what I'm trying. I have and array that I'm storing all the letters
of the alphabet, and I also want to count how many times a users 1st letter
of their last name match that letter in the alphabet. I created the array
as follows:

<cfset alphaList=arraynew(2)>
<cfset alphaListLoop="A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R ,S,T,U,V,W,X,Y,Z">
<cfset alphaLoopCount=1>
<cfloop list="#alphaListLoop#" delimiters="," index="i">
<cfset alphaList[#alphaLoopCount#][1]=#i#>
<!--- send to udf to count each letter occurance and assign
to variable --->
<cfinvoke component="components.reccount" method="getinfo"
returnvariable="result">
<cfinvokeargument name="alpha" value="#i#">
</cfinvoke>
<cfset alphaList[#alphaLoopCount#][2]=#result#>
<cfset alphaLoopCount=alphaLoopCount+1>
</cfloop>

So each letter is assigned, and the automatic count is set to 0.

The problem comes when I'm using the <cfinvoke>, here's the code for that:


<cfcomponent displayname="reccount" hint="Counts all records with a specific
1st letter">
<!--- This function retrieves all customers from the database --->
<cffunction name="getinfo"
hint="Counts records" returntype="numeric" output="no">
<cfargument name="alpha" required="yes" type="string">
<cfset var result = 0>
<cftry>
<cfquery name="CountRec" datasource="SalleBoise">
SELECT Cust_Name FROM inforeq
</cfquery>

<cfloop query="CountRec">
<cfset tmpLname=(findnocase(" ",#CountRec.Cust_Name#) + 1)>
<cfset tmpLname2=left(mid(LastRegistered.Cust_Name,tmpLna me,(tmpLname-1)),1)>
<cfif tmpLname2 eq #arguments.alpha#>
<cfset result=result + 1>
</cfif>
</cfloop>

<cfcatch type="any">
<cfset result = false>
</cfcatch>
</cftry>
<cfreturn result />
</cffunction>
</cfcomponent>

When I try to run the code, I'm getting:

Complex object types cannot be converted to simple values.
The expression has requested a variable or an intermediate expression result
as a simple value, however, the result cannot be converted to a simple value.
Simple values are strings, numbers, boolean values, and date/time values.
Queries, arrays, and COM objects are examples of complex values.

Where did I go wrong?????




Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 10-07-2008, 05:30 PM
Azadi
 
Posts: n/a
Diggs:
Default Re: Array and CFC question

that's some code...

how about:

SELECT COUNT(Cust_Name) AS totalcount
FROM inforeq
WHERE UPPER(SUBSTRING(Cust_Name, LOCATE(' ', Cust_Name)+1, 1)) =
<cfqueryparam cfsqltype="cf_sql_varchar" value="#ucase(arguments.alpha)#">

[this is mysql syntax, but other DBs will have equivalent functions]

the query will return totalcount - number of records where the second
word in Cust_Name column begins with a given #alpha# letter.


Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/
Reply With Quote
  #3 (permalink)  
Old 10-07-2008, 05:30 PM
steve grosz
 
Posts: n/a
Diggs:
Default Re: Array and CFC question

Hello Azadi,

Thanks....not sure if that's a good comment or not....

So, you're saying try your code if the CFC instead of what I have?

> that's some code...
>
> how about:
>
> SELECT COUNT(Cust_Name) AS totalcount
> FROM inforeq
> WHERE UPPER(SUBSTRING(Cust_Name, LOCATE(' ', Cust_Name)+1, 1)) =
> <cfqueryparam cfsqltype="cf_sql_varchar"
> value="#ucase(arguments.alpha)#">
> [this is mysql syntax, but other DBs will have equivalent functions]
>
> the query will return totalcount - number of records where the second
> word in Cust_Name column begins with a given #alpha# letter.
>
> Azadi Saryev
> Sabai-dee.com
> http://www.sabai-dee.com/



Reply With Quote


  #4 (permalink)  
Old 10-07-2008, 05:30 PM
Dan Bracuk
 
Posts: n/a
Diggs:
Default Re: Array and CFC question

What db are you using? You might be able to do it with sql.
Reply With Quote
  #5 (permalink)  
Old 10-07-2008, 05:30 PM
steve grosz
 
Posts: n/a
Diggs:
Default Re: Array and CFC question

Hello Dan,

This is on a MySql database

> What db are you using? You might be able to do it with sql.
>



Reply With Quote
  #6 (permalink)  
Old 10-07-2008, 05:52 PM
Dan Bracuk
 
Posts: n/a
Diggs:
Default Re: Array and CFC question

I don't use mySql, but this is the approach I would take. I'm stealing Azadi's
syntax for the part where you find the first letter in the last name.

letters = 'A,B,C,...Y';

SELECT TheLetter, COUNT(TheLetter) AS totalcount
FROM inforeq
left join
(<cfloop list = "#letters# index = "ThisLetter">
select distinct '#ThisLetter#' TheLetter
from SomeSmallTable
union
</cfloop>
select distinct 'Z' TheLetter
from SomeSmallTable) sq on TheLetter = UPPER(SUBSTRING(Cust_Name, LOCATE(' ',
Cust_Name)+1, 1))


You might have to change this:
COUNT(TheLetter)
to something like this
ifnull(COUNT(TheLetter), 0)

or you might not

Reply With Quote


  #7 (permalink)  
Old 10-07-2008, 06:02 PM
Azadi
 
Posts: n/a
Diggs:
Default Re: Array and CFC question

good idea, Dan! i might use that someday instead of my usual concoction
of querynew(), structuses and lists...

just... shouldn't it be RIGHT JOIN so the query selects all letters of
the alphabet?

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/
Reply With Quote
  #8 (permalink)  
Old 10-07-2008, 09:54 PM
Dan Bracuk
 
Posts: n/a
Diggs:
Default Re: Array and CFC question

[q]Originally posted by: Newsgroup User
good idea, Dan! i might use that someday instead of my usual concoction
of querynew(), structuses and lists...

just... shouldn't it be RIGHT JOIN so the query selects all letters of
the alphabet?

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/
[/q]
It is right join. Newsgroup users don't get to see edits. Besides, it's
Steve's jobs to work out the details.

Reply With Quote
  #9 (permalink)  
Old 10-07-2008, 10:00 PM
steve grosz
 
Posts: n/a
Diggs:
Default Re: Array and CFC question

Hello Dan,

I did get it working. Thanks to the both of you for your help!

> [q]Originally posted by: Newsgroup User
> good idea, Dan! i might use that someday instead of my usual
> concoction
> of querynew(), structuses and lists...
> just... shouldn't it be RIGHT JOIN so the query selects all letters
> of
> the alphabet?
> Azadi Saryev
> Sabai-dee.com
> http://www.sabai-dee.com/
> [/q]
> It is right join. Newsgroup users don't get to see edits. Besides,
> it's
> Steve's jobs to work out the details.



Reply With Quote


Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



© Camley Interactive (camley.info) 2008 - all logos and images are copywrite their respective owners.
Proud member of the Camley Interactive Network
All times are GMT. The time now is 12:48 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
Inactive Reminders By Mished.co.uk