Solved

Finding the max entered in the fields

Posted on 2007-11-26
8
164 Views
Last Modified: 2010-04-06
Ok, I have 6 numeric textfields. I want to display the max of the 6 fields. How can I do this? The only appraoch I had in mind is with a list, but I know there's another way. maybe a quesry loop on the 6 fields to find the max? HELP
0
Comment
Question by:FIATECH
  • 4
  • 4
8 Comments
 
LVL 52

Expert Comment

by:_agx_
ID: 20352411
Can you give an example of what you mean with the desired results?
0
 

Author Comment

by:FIATECH
ID: 20352434
yes. <cfoutput>#biggestnumber#</cfoutput>

if 10, 89, 35, 3, 5, 78 was entered I just want to get the saved result in the DB to display. SO maybe I can pull those variables from the DB and just show the max? Its sounds so easy but I can't do it!
0
 
LVL 52

Expert Comment

by:_agx_
ID: 20352453
If they values are entered into a column named "ColumnA" you could just use MAX

<cfquery name="yourQuery" ...>
SELECT MAX(ColumnA) AS biggestnumber
FROM   YourTable
</cfquery>

<cfoutput>#YourQuery.biggestnumber#</cfoutput>
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

Author Comment

by:FIATECH
ID: 20352473
well i don't want to pull the whole column. only those 6 values from that column.
0
 
LVL 52

Expert Comment

by:_agx_
ID: 20352499
How do you identify the 6 values, by ID or are they stored as a comma delimited list, or something else?  In other words what is a sample of the table data you're using?
0
 

Author Comment

by:FIATECH
ID: 20352516
I want these only form the table

<cfset A_day04_3=getdata.A_day04_3>
<cfset A_day05_2=getdata.A_day05_2>
<cfset A_day10_4=getdata.A_day10_4>
<cfset A_day11_3=getdata.A_day11_3>
<cfset A_day12_2=getdata.A_day12_2>
<cfset A_dayothe=getdata.A_dayothe>
0
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
ID: 20352615
One option is use a union query

<cfquery name="getBiggestNumber" ...>
  SELECT  Max(TheNumber) AS BiggestNumber
  FROM  (
  SELECT A_day04_3 AS TheNumber FROM YourTable
  UNION
  SELECT A_day05_2 AS TheNumber FROM YourTable
  UNION
  SELECT A_day10_4 AS TheNumber FROM YourTable
  UNION
  SELECT A_day11_3 AS TheNumber FROM YourTable
  UNION
  SELECT A_day12_2 AS TheNumber FROM YourTable
  UNION
  SELECT A_dayothe AS TheNumber FROM YourTable
  ) AS t
</cfquery>

Another is to put the values into an array and use arrayMax

<cfset list = "#getdata.A_day04_3#,#getdata.A_day05_2#,#getdata.A_day10_4#,#getdata.A_day11_3#,#getdata.A_day12_2#,#getdata.A_dayothe#">
<cfset biggestnumber = arrayMax(listToArray(list))>
<cfoutput>
#biggestNumber#
</cfoutput>



0
 

Author Comment

by:FIATECH
ID: 20352634
Thanks I like the list array! THANKS! Let me try it now!
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
replace quotes with UTF-8 character 38 105
Form submit issue 11 86
Grunt Copy file to another destination. 1 56
BACKUP of mysql database from mysql server - using Coldfusion 9 42
This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

861 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