Random Display of Query Results (no repeats)

First of all, I am a ColdFusion novice, so please forgive me
if the answer to this is either blantantly obvious or totally
impossible. Here is my problem.
I am querying a database with several hundred records. The
query will return on average between 10 - 15 records. I then want
to display 2 of these records on a random basis. I do have this
much working. The only problem is that every so often, the 2
records that are displayed are the same record. I need to avoid
this outcome. The 2 records should always be different.
Here is a simplified version of my code:
<CFQUERY name="queryname" datasource="datasourcename">
SELECT * FROM Residential
WHERE ListingOfficeName = 'Widner Realty'
</CFQUERY>
<cfset randRecordsList = ''>
<cfloop from="1" to="2" index="i">
<cfset randVal = randRange(1,queryname.recordCount)>
<cfset randRecordsList = listAppend(randRecordsList ,
randVal)>
</cfloop>
<cfloop list="#randRecordsList#" index="i">
<cfoutput>
#queryName.FieldName1
#queryName.FieldName2#
#queryName.FieldName3
#<br>
</cfoutput>
</cfloop>
Any help would be appreciated. Thanks in advance.

Here is the general idea. You can look after the specifics.
// generate list of numbers.
maxnum = 15;
numlist = "";
for (i = 1; i lte maxnum; i = i + 1)
numlist = listappend(numlist, i);
// randomnums will have the two random numbers
RandomNums = "";
x = true;
while (x is true) {
ThisNum = RandRange(1, maxNum);
if (ListFind(RandomNums, ThisNum) is false)
RandomNums = ListAppend(RandomNums, ThisNum);
if (ListLen(RandomNums) is 2)
x = false;
}

Similar Messages

  • How to display the query results in several pages?.

    Hi,
    i want to display the query results in several pages. for example my query result found 50 matches, now i want to print 20 per pages next 20 will be in next pages. iam using only jsp & mysql.
    Regards
    Chinna

    Hi, what you are trying accomplish is known as pagination.
    You could use JSTL tags with Custom Tags to perform pagination in your JSP pages.
    evnafets showed me DisplayTags , you could use those as well http://displaytag.sourceforge.net/11/tut_externalSortAndPage.html
    Here is one article on paging:
    http://www.javaworld.com/javaworld/jw-07-2004/jw-0726-pagination.html

  • Display the query result in an Excel file??

    hi there..
    am writing one script file that queries my DB and display the query result in an Excel file??
    i.e: if my query is :
    select col1, col2
    from table;
    and i want the results to dispalys in 2 col. in an Excel spreadsheet..
    Appreaciating ur cooperation..
    Mourad

    set colsep to a delimiter that is not normally part of your data like |
    also setup the environment with these other setup commands
    Set Echo Off;
    Set Concat Off;
    Set Pagesize 9999;
    Set Feedback Off;
    Set Verify Off;
    Set Term Off;
    Set Space 0;
    Set Colsep '|'
    Set Underline Off;
    If you wanted to use a comma delimiter the setup would be same but the set colsep='","'
    with the addition of concatenating a " on the first col and last col of the query
    eg.
    -- if first col and last_col are character types then
    SELECT '"'||col1,....,last_col||'"'
    FROM table;
    Otherwise if either is a number they would have to be converted with a TO_CHAR

  • QA: Designer's operation to Add one more Field to display in Query Result Web Part

    QUESTION ABOUT Query Result Web Part presentation +1 Field
    I'd be looking at a property of Web Part to look up Discussion Board through Query Result Web Part. Currently it displays 'Title' column of Discussion Board, and my caring requirement is presentation customization to hold double
    columns of 'Title'+'Updated Date'. How could I add one more field 'Updated Date' to display in addition to that preexisting 'Title' field?
    Any procedural steps to realize how to add Filed to display in Query Result Web Part?

    Hi Yoshihiro,
    As I understand, you want to add the field to display in Query Result Web Part in SharePoint 2013.
    Which web part does you use? Content query web part or search results web part?
    If you use search results web part, you could edit the discussion board result template and add the updated field in the template.
    You could go to Design Manager: Edit Display Templates (site setting-> look and feel->design manager->edit display template), download the Discussion Item.htm file, and edit the file. 
    After editing, upload the file.
    The articles below are about how to modify an existing Display Template in SharePoint 2013.
    http://www.learningsharepoint.com/2012/09/17/sharepoint-2013-the-new-display-templates-for-styling-your-content/
    http://blogs.technet.com/b/sharepoint_quick_reads/archive/2013/08/01/sharepoint-2013-customize-display-template-for-content-by-search-web-part-cswp-part-1.aspx
     If you use content query web part, you could edit the content query web part, in the Property Mappings section select the “Change the mapping of managed”, and add the “modifiedOWSDATE” (it means the last modified date) in the line, after
    that you could see the update date under the title.
    Best regards,
    Sara Fan
    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected]

  • Display dynamic query result in collection

    How to we put the query results in collection for a dynamic query?

    Do you want to display or to store or do both.
    Anyway try a check at this:
    http://forum.java.sun.com/thread.jspa?threadID=584195&messageID=2991930#2991930
    I think if u do the reverse process you will be able to retrieve the values from the list and display them.
    Try giving a thought.

  • Displaying SQL Query results in rows instead of Columns

    Hi,
    I'm fairly new to Oracle so forgive me if this is a really stupid question.
    I used Mysql for a while and if I wanted to display query results in rows instead of columns I could end the SQL command with '\G' instead of a semicolon.
    This would give me output like...
    Column_1: AAAA
    Column_2: BBBB
    Column_3: CCCC
    Instead of the normal
    Column_1 Column_2 Column_3
    AAAAAA BBBBBBB CCCCCCC
    Is there an equivalent in SQLPlus to the MySQL \G termination?
    Thanks.
    John

    > so forgive me if this is a really stupid question.
    It is certainly not a stupid question, but pivoting is a very frequently asked and answered question:
    [url http://forums.oracle.com/forums/search.jspa?threadID=&q=pivot&objID=f75&dateRange=all&userID=&numResults=15]http://forums.oracle.com/forums/search.jspa?threadID=&q=pivot&objID=f75&dateRange=all&userID=&numResults=15
    In 11g you have special PIVOT and UNPIVOT functions.
    Regards,
    Rob.

  • How to display MySql query results in multiple columns?

    Hi, I know how to display PHP/MySq
    l query results in a single column, but I am really stuck at displa
    ying the results in multiple columns in DW CS4.
    Can anyone help me with a code example?. I am new to php/mysql. Thanks

    Are you asking how to pivot the results of the query? Do a search for horizontal looping. If that's not what you are asking, please provide more details.

  • Display content query results horizontally

    Hi,
    Is there an easy way to configure the content query web part to display results horizontally?
    thanks,
    Sherazad

    Would this help?
    Rendering Content Query Web Part
    results in Table Layout
    Amit

  • Display Sql query result

    i have a c++ form that accepts data and saves it on a table in a database via a button click, this is the code for the eventprivate: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
    String^ constring=L"datasource=localhost;port=3306;username=root;password=lampard";
    MySqlConnection^ conDatabase=gcnew MySqlConnection(constring);
    MySqlCommand^ cmdDatabase=gcnew MySqlCommand("insert into test.Data(Full_Name,Matric_No) values('"+this->textBox1->Text+"','"+this->textBox10->Text+"') ;" ,conDatabase);
    MySqlDataReader^ myReader;
    try{
    conDatabase->Open();
    myReader=cmdDatabase->ExecuteReader();
    MessageBox::Show("Saved");
    while(myReader->Read()){
    }catch(Exception^ex){
    MessageBox::Show(ex->Message);
    NOW i want to send a query to give out this information in a new form or in a form exactly like the one used to enter the data, this is how far i have come
    private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
    this->Hide();
    MyForm ^ Form = gcnew MyForm(this);
    Form->ShowDialog();
    String^ constring=L"datasource=localhost;port=3306;username=root;password=lampard";
    MySqlConnection^ conDatabase=gcnew MySqlConnection(constring);
    MySqlCommand^ cmdDatabase=gcnew MySqlCommand("Select * from test.Data where Matric_No='"+textBox1->Text +"';",conDatabase);
    MySqlDataReader^ myReader;
    try{
    conDatabase->Open();
    myReader=cmdDatabase->ExecuteReader();
    while(myReader->Read()){
    textBox1->Text ;
    }catch(Exception^ex){
    MessageBox::Show(ex->Message);
    NOte: MyForm is the title of the form used to enter in the data sent to the database please how do i get the program to display the data meeting the query criteria into a form?

    i made textBox1 a public memeber of MyForm class and i changed  
    Form->ShowDialog(); to Form->Show() and i entered the code you advised me to and it displayed the result.i am very grateful, thank you

  • Displaying SQL query results in tabular fashion

    Hi,
    I've a table having following three fields."Market segment","Status","No of Cust".
    This table contains the name of market segment, name of user status(4 in no) and number of customers belonging to that status.
    I need to create a query that will show the result in a tabular manner.like the following
    Market segment.....status1.....status2........status3.......Total
    MS1...................... 5..............6............... 7................18
    ms2........................1..............6................8...............15
    Total.......................x..............y.................z................T
    (Ignore the dots(.))
    Can some one help me with the query?
    Thanks,
    jajati

    See this link:
    http://tonyandrews.blogspot.com/2004/10/pivot-queries.html

  • Changing the display of query results on web

    Hi,
    Whenever I execute a query in IE, the standard report that comes up displays only 4 columns. Where can I change this number of columns that will be displayed?
    I checked in RSCUSTV27 for the web template for Ad Hoc reporting, where there was no template specified. In case there is no template specified, it is going to use a standard 0QUERY_TEMPLATE web template for this. I could not find this standard web template in both active content and BI content.
    Thanks,
    Sanjeev

    Hi,
    The standard web template is 0ANALYSIS_PATTERN, please open that in WAD and do the needful.
    Thanks
    Dipika

  • Problem viewing Query Result

    Hi- I occasionally come across this issue when I run any query in SQL Developer (3.0.02), the Query Result tab shows a bold red Exclamation point and the display grid is blank. It says "Fetched 50 rows in 0.235 seconds" but the results aren't displayed. There is nothing wrong with the queries so it seems like some type of display problem but I can't figure out how to fix it. Like I said, it doesn't happen all the time and I run the same saved queries so I know it's not a problem with the actual queries. Has anyone ever seen or heard of this before?

    Hi,
    Sounds like you are using an early adopter version of 3.0. Why not upgrade to the latest production release (3.1.07.42)?
    A similar situation is described in this old thread:
    Re: Randomly not getting query results
    Regards,
    SQL Developer Team

  • Display Crosstab query in DataGrid

    Hi, I'm a Flex beginner. Could someone please help me how to
    display crosstab query result in DataGrid? The following query
    returns 6 columns:
    - First column: values in the field Sell_Channel
    - Second: Sum(Revenue Total) from the Revenue field.
    - Others: Revenue Subtotal by Sell_Channel and quarter.
    Quarters are values stored in the field name Quarter. In Datagrid,
    what would be the datafield for these 4 quarter columns?
    Thanks millions.
    Here is my SQL:
    TRANSFORM Sum(Revenue.RevenueTotal) AS SumOfRevenueTotal
    SELECT Revenue.Sell_Channel, Sum(Revenue.RevenueTotal) AS
    [Total Of RevenueTotal]
    FROM Quarter INNER JOIN Revenue ON Quarter.FiscalQuarter =
    Revenue.Quarter
    WHERE (Revenue.Fiscal_Year="2006")
    GROUP BY Revenue.Sell_Channel
    PIVOT Quarter.Quarter;

    Crosstab is a reporting function not a SQL one. SQL statements must have a fixed number of columns regardless of the data.
    The only way to do it using SQL is to use PL/SQL to generate a dynamic query as shown on Ask Tom here
    http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:15151874723724
    Otherwise there are reporting tools such as Oracle Reports that can do it as well.

  • Many to Many - display query result?

    Greetings
    In a help desk app, the manager can assingn more than one technician to a project.
    Whe he or she assigns a project, the tech ID & project ID are inserted in a junction table. This works fine.
    The description, assigned date & due date field are static- the resolution (textarea) needs to be added to as the project progesses, as well as hours spent by each tech.
    I am running into problems displaying what the technician sees on their "contol panel".
    When the tech views the details of an ongoing project, I am getting cartesian product results.
    The tech needs to add to the resolution (textarea),  view who else is working on the project, and how many hours each has contributed.
    The project display page query:
    SELECT DISTINCT project_ID, project_num, project_desc, project_res, assign_date, assign_time, due_date, complete_dte, complete_time, assigned,
    tech_1_hours, tech_2_hours, tech_3_hours, tech_4_hours, tech_ID, junc_tech_ID, junc_project_ID
    FROM main_projects, lookup_tech, junction_project_tech
    WHERE tech_ID = #Session.user_id#
    AND project_ID = #URL.project_ID#
    AND project_ID = junc_project_ID
    AND tech_ID = junc_tech_ID
    And the math;
    <cfset 'total' = (#tech_1_hours#+#tech_2_hours#+#tech_3_hours#+#tech_4_hours#)>
    The project display repeats itself for every technicain-
    Any help with this would be greatly apprecaited.
    24 month to retirement!
    Norman

    Hi,
    Will all Students have exactly two Teachers?
    If not picture your sample with two more Students.
    One having 1 Teacher
    One having N Teachers
    Think about N, what will it be? - How would you create a table with N columns?
    If you can't easily answer above, re-consider what you are trying.
    That said, it could still be done - even if all Students do not have exactly two Teachers - and is called Pivot a dynamic number of columns.
    Examples are in FAQ
    SQL and PL/SQL FAQ
    Still a bad idea, with or without known number of teachers
    Regards
    Peter

  • Options to control display performance of CLOBs, etc. in Query Result view?

    Whenever I attempt to query a table that contains LOBs (e.g. a CLOB or XMLTYPE), the lack of performance pretty much makes the "Query Result" view (from F9) unusable. Any time I attempt to scroll the results, SQL developer apparently continues to query the database for the additional characters to populate the view.
    Resizing the columns containing the LOB to only a few characters almost solves the issue. Unfortunately, the size of the columns showing the LOBs apparently attempt to resize to the length of the LOB, making the column several pages long - and the same performance issue prevents resizing it smaller.
    Ideally, there would be some way to resize a column to a given or even a predefined and small size, without having to drag the resize handle the entire width of the desired resize amount. Alternatively, there could be a user preference to never set default column widths above a given number of pixels or characters. Another option would be a user preference to disable the in-line display of LOB contents, displaying only and requiring a click on the "..." (or pencil icon) button to open the "View Value" dialog. Ideally, all 3 of these options could be implemented.
    One crude work-around I'm using for now is to exclude the LOB columns from the results, requiring me to make secondary queries to see the LOB contents when necessary, and doesn't allow for scrolling through and viewing the LOB contents at all. Another work-around is to run the query as a script (F5) instead of a query (F9), and view the results in the "Script Output" view instead.
    I'm currently using SQL Developer 2.1.0.63, but experienced this same issue with all previous versions, including 1.5.5.
    Thanks!

    I agree.
    When I requested to auto-width the columns, I said to build in a maximum, but apparently they didn't.
    I suggest you log 2 feature requests on the SQL Developer Exchange; 1 for the maximum width, 1 for the CLOB contents/performance. Like this others can vote too and add weight for future implementation (I will).
    Have fun,
    K.

Maybe you are looking for

  • How can I use one gmail address on two different macbooks in 'mail'?

    I'm using one business gmail address. Me and my girlfriend both have a macbook. Now the gmail address is linked to my macbook. But she wants to use it as well. Unfortunately the 'mail' system won't allow her to sync with the gmail address. And I get

  • Parenting and child control with AS3

    Hi, I'm new to AS3 and although I can see some good practice and functionality I'm constantly getting stucked and can't yet make things that I would do so easily with AS2 - I almost need to relearn it from scratch!. Still I would appreciate some help

  • Recurring mDNSResponder request on port 5354 after 10.5.7?

    Since installing 10.5.7 I get a a network request from pm-members.mac.com for mDNSResponder on port 5354. I have Little Snitch and even if I authorize it forever, this request keeps on popping up on startup and exit. I was wondering if anyone knew ho

  • Printed Docs Not Following TOC

    When you generate a printed doc (in this case, Word output), you are supposed to get output of topics in a sequence that follows the TOC as outlined on the TOC panel in RoboHelp. Instead, I am getting a complete jumble, with some topics even repeated

  • Don't understand how to transfer from iWeb to personal website

    I have created a website on iWeb but I don't understand how to transfer it to my own domain name through my university. I'm not very good with technology and don't really understand what an FTP is. Is that what I would use Dreamweaver for? So confuse