Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6655493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:31:35+00:00 2026-05-26T01:31:35+00:00

I am using ColdFusion 9.1. I am coding using CFSCRIPT. I am creating a

  • 0

I am using ColdFusion 9.1. I am coding using CFSCRIPT.

I am creating a quiz. Query one will go get an image of a person and the person of the person in the image. This will be the correct answer. Query two will go get two other people who are not in the image. I want to put this into an array and then sort the array so that the correct answer isn’t always at the top or the bottom or in the middle.

Here is my pseudo SQL:

QUERY ONE NAME = GET CORRECT ANSWER
SELECT TOP 1 ImageID, PersonID, FirstName, LastName
FROM IMAGES

QUERY TWO NAME =  GET TWO INCORRECT ANSWERS
SELECT TOP 2 PersonID, FirstName, LastName
FROM IMAGES 
WHERE ImageID IS NOT THE CORRECT ANSWER

I “think” I want my array to look like this:

PersonID="1234";
FirstName="Bob";
LastName="Jones";

I need to loop through each query and populate this array with the three people returned from the query. Like this, but this code doesn’t work:

<cfscript>
PersonArray = arrayNew(1);
for (i = 1; i lte GetTwoWrong.RecordCount; i++) {
    Person = structNew();
    Person.PersonID = GetTwoWrong.PersonID[i];
Person.FirstName = GetTwoWrong.FirstName[i];
Person.LastName = GetTwoWrong.LastName [i];
PersonArray = arrayAppend(PersonArray , Person);

}
</cfscript>

Then I need to sort the array by FirstName, LastName, or PersonID to create any kind of randomness.

<cfscript>
PersonArray = arraySort(PersonArray numeric);
</cfscript>

Then I will need to output the answers. The answer will be clickable. On click, I will send the PersonID via jQuery to check the answer for correctness (and store the selection).

So, how do I create an array and then populate it from two different queries and then sort it? Should I be using an array at all? A structure?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T01:31:35+00:00Added an answer on May 26, 2026 at 1:31 am

    I would do this in the database, which will be far less complicated. Here’s an example:

    SELECT * FROM (
        SELECT TOP 1 1 AS Correct, ImageID, PersonID, FirstName, LastName, UniqueToCorrectAnswer
        FROM IMAGES
        UNION ALL
        SELECT TOP 2 0 AS Correct, ImageID, PersonID, FirstName, LastName, NULL AS UniqueToCorrectAnswer
        FROM IMAGES 
        WHERE ImageID IS NOT THE CORRECT ANSWER
    ) AllAnswers
    ORDER BY NewID()
    

    The two queries on either side of the UNION can be totally different against different databases, tables, and criteria, so long as they both return the same columns. You’ll notice in the second query, I’m returning a NULL value for something that doesn’t exist there, but does exist in the first one (just an example). So you can see how you can return different values from each side of the UNION and get them in a completely random order.

    This is something that database servers are much better at than application code. If you need to (somewhere on the page) deal with your correct and incorrect answers differently, you can then use a Query of Query to pull just the correct or incorrect answers out of the base query.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using ColdFusion with Microsoft SQL Server 2005 and on occasion I get this
I'm trying to obtain credentials from ning network using Coldfusion 9, so first this
I'm using ColdFusion to populate a template that includes HTML unordered lists ( <ul>
I'm using ColdFusion to return a result set from a SQL database and turn
Using CFML (ColdFusion Markup Langauge, aka ColdFusion), how can you compare if two single
I have a web application, written in ColdFusion, which periodically starts using 100% of
coldfusion.compiler.FactoredNodeAggregation cannot be cast to coldfusion.compiler.ASTfunctionDefinition I get the above error when attempting to
I'm using Coldfusion. I want to concatenate two strings into the same struct key,
I am using Coldfusion 8 which is connecting to SQL Server 2008, the problem
I am currently using Shapefile class and ColdFusion to go through the records of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.