EasyCFM.COM ColdFusion Forums / Coding Help! / Specific Recordcount

   Reply to Discussion | New Discussion << previous || next >> 
Posted By Discussion Topic: Specific Recordcount -- page: 1 2 3

book mark this topic Printer-friendly Version  send this discussion to a friend  new posts last

ArVark
09-12-2006 @ 8:22 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
New Member
Posts: 25
Joined: Aug 2006

Is it possible to output specfic recordcounts?

Like <CFOUTPUT>queryname.record4.columnname</CF...

I'm trying to output 5 links, but all around a page and I'm drawing a blank. So far all I can come up with is far too many CFIF statements checking the recordcount and outputting accordingly.

JJfutbol
09-12-2006 @ 9:10 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 1250
Joined: Nov 2004

I don't think I follow what you are trying to do mate? Why do you need a more specific recordCount? Or rather it won't even exist because if you are in a record that is part of the count but there are no records within a record so no count will be there. Unless, are you looping through the columns as well and did you want to do a count of that??

----------------------------------------------------
Some free CF applications available at my site, such as the popular CFC Validator www.javier-julio.com My new site design is up!! Let me know what you all think! Working on a fully accessible Forum, which validates as full CSS and XHTML 1.0 Strict.

ArVark
09-12-2006 @ 9:32 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
New Member
Posts: 25
Joined: Aug 2006

I want to output a query of 5 links. There are about 50 links, but I only want 5. I will either pull them by number of hits or randomly pull them out.

When I output them, I don't want them to be in the standard output table or list. I want them scattered all around the page. There will be two other queries doing the same thing with links from different categories.

There may be another way to do this, but I was thinking about outputting each of the five links based on it's unique location in the query. I can do record count, but I can't figure out how to pull out a specific record from the query. Not a specific record from the DB, I would use the ID in that case, but does the query have any ID or key unique to itself. I know it has an attribute of queryname.recordcount, but can I access each one?

megan
09-12-2006 @ 9:42 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 2398
Joined: Jan 2003

It's kind of hard to know what you are after but just guessing you might do something like this

<!--- do your query --->
query here
<!--- loop through your query --->
<cfloop query="myquery">
<cfset myVar#currentrow# = "#mycolumn#>
</cfloop>

Then supposing you know how many records you have being output

<cfoutput>#myvar1#</cfoutput> goes here

<cfoutput>#myvar3#</cfoutput> goes there

just one idea - I'm sure other people will have other ideas for example you could use an array

<cfset arrmyFields = arrayNew(1)>
<cfloop query="myquery">
<cfset arrmyFields[#currentrow#] = "#myFieldContent#">
</cfloop>

and then <cfoutput>#arrmyFields[1]#</cfoutput>

if these have to be output on every page you might want to set up everything in the application.cfm as a request variable

hth ~megan


We have art so that we shall not die of reality ~ Nietzsche

megan
09-12-2006 @ 9:44 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 2398
Joined: Jan 2003

Hi You must have posted while I was typing Smile  - I think what you are looking for is #currentrow# - hope that helps, megan

We have art so that we shall not die of reality ~ Nietzsche

JJfutbol
09-12-2006 @ 9:45 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 1250
Joined: Nov 2004

You are overcomplicating what a query and queryName.recordCount do I think. If you just want to display the first 5 records of a 50 record query you have several options. When looping you could simply test that if the queryName.currentRow is greater than 5 to 'break' out of the loop.

Another option you have is to modify the cfquery tag by using the maxrows attribute and set it to 5 so that you only ever get 5 records. There are also ways to get a random set of records but depends on the database you are using as it varies.

----------------------------------------------------
Some free CF applications available at my site, such as the popular CFC Validator www.javier-julio.com My new site design is up!! Let me know what you all think! Working on a fully accessible Forum, which validates as full CSS and XHTML 1.0 Strict.

JJfutbol
09-12-2006 @ 9:49 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 1250
Joined: Nov 2004

I think Megan has it down right as well, it seems you might not know about the currentRow property in a cfquery. If thats the case shame on you for not knowing about its existence! It's time you did some readin son, you got homework. Wink

cfquery tag
http://www.techfeed.net/cfQuickDocs/?getDoc=cfquery

If you scroll down on that page past the first bordered table you see the Docs will list out the 3 objects that become available when you use a cfquery tag. Although there is 4 now if you read the very beginning part of the docs as it states queryName.executionTime was added to a new version of CF.

----------------------------------------------------
Some free CF applications available at my site, such as the popular CFC Validator www.javier-julio.com My new site design is up!! Let me know what you all think! Working on a fully accessible Forum, which validates as full CSS and XHTML 1.0 Strict.

daddyFL
09-12-2006 @ 10:05 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 373
Joined: Jan 2006

If you are looking to pull the links randomly, Megan suggested an Array which will work if you do the following:

1)Populate your query results into an Array

2)Create a random number from 1 to the number of records coming from the query.
<cfset randNums1 = RandRange(1,Query.RecordCount)>
<cfset randNums2 = RandRange(1,Query.RecordCount)>
<cfset randNums3 = RandRange(1,Query.RecordCount)>
<cfset randNums4 = RandRange(1,Query.RecordCount)>
<cfset randNums5 = RandRange(1,Query.RecordCount)>

3)Output your random array element in your script
<cfoutput>#myArray[randNums1]#</cfoutput>
<cfoutput>#myArray[randNums2]#</cfoutput>
<cfoutput>#myArray[randNums3]#</cfoutput>
<cfoutput>#myArray[randNums4]#</cfoutput>
<cfoutput>#myArray[randNums5]#</cfoutput>


Thanks

ArVark
09-12-2006 @ 10:08 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
New Member
Posts: 25
Joined: Aug 2006

What I want to do is select a specific recordcount. When the five links are in the query I want to pull out queryname.recordcountNumber3.column

So if the column is called Last Name, I want to be able to pull out the 3rd or 4th recordcount for Last Name of the query.

I'll try Megan's idea. I wasn't sure about how to loop them into an array. I'm not comfortable with loops though I copy and paste them all the time.

Once again since perhaps I am not using the correct terminology.

I can pull out the 5 rows with no problem. I can use LIMIT 5 in MySQL or MaxRows = 5 or break out of the loop at 5, that's not what I need to do. I could display them in a straight table TR TD set up if I needed, but I need to pull specific records from the query (not the DB) at different locations on the page. I might have one record in the upper left, another one in the lower right of the page. They would be all over the page.

This message was edited by ArVark on 9-12-06 @ 10:11 AM

daddyFL
09-12-2006 @ 10:18 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 373
Joined: Jan 2006

I thought you wanted to randomly pull the links? I provided you with a solution that gave you the dynamic effect you were looking for, allowing you to place the links anywhere on your page without a problem.

Maybe I misunderstood what you are looking to do.

Thanks

PAGE: 1 2 3

Website Designed and Developed by Pablo Varando.