Random Record Display

Can someone tell me how to display a random record from a database? I want to use it on my site to show a "review"... am able to do it in ASP but not sure how to in JSP.
Any advice is gratefully received.
M

ok man
you can put all object that you get it form DB in not
sorted contener as HashMAP. okYeah, then to further randomize it, you can use a Random Number to lookup in that HashMap. ;) Sounds interesting.
Annie.

Similar Messages

  • Random Record from a Query

    I have a page on my site that displays certain information in
    kind of a "feature" section, where it needs to query the database
    based on certain criteria and then display the data for just one of
    the records. The record should be different each time the page
    loads. So, if my query has 10 or 20 records, I just want to select
    one of them randomly and disply its data. What would be the best
    way to code such a scenario?
    Many thanks.

    first, a statement that contains "The record
    should be different each time the page loads" and "select one
    of them
    randomly and display its data" is a bit of a contradiction:
    you either
    display a random record or you control which record to
    display to make
    sure each page load displays a different one.
    if you just want a random record displayed (which means same
    record may
    be displayed on subsequent page loads) then how to do it
    depends on
    which database you are using, as cfSearching pointed out.
    here's a great place to look to sql statements for this for
    various db
    systems:
    http://www.petefreitag.com/item/466.cfm
    if you want to display a different record each page load, you
    need to
    keep track which records have already been displayed
    previously and
    display the next one in sequence. you could do this by
    storing the list
    of record ids in an application-scope variable, displaying
    the record
    with the first id and removing that id from the list of ids.
    when the
    list is empty, query the db for record ids again and make a
    list anew.
    hth
    Azadi Saryev
    Sabai-dee.com
    http://www.sabai-dee.com/

  • Display Random Record

    Morning all
    Just a quick one.
    How do I display a random record in DW?
    I have a MySQL statement which is:
    SELECT * FROM
    tablename ORDER BY RAND() LIMIT 0,
    number of records to display
    The error message I get is:
    'Syntax error (missing operator) in query expression RAND()
    LIMIT 0'
    If I alter 'RAND()' to 'RND()', I still get the error. If I
    remove the '0' I still get the error.
    Any ideas how to make this work?
    I'm using Access BTW.
    Regards
    Martin

    Tell your SQL statement what to RAND - right now it doesn't
    know how to
    randomize it, by what field.
    "Pantyboy" <[email protected]> wrote in
    message
    news:ef0and$r7g$[email protected]..
    > Morning all
    >
    > Just a quick one.
    >
    > How do I display a random record in DW?
    >
    > I have a MySQL statement which is:
    >
    > SELECT * FROM
    tablename ORDER BY RAND() LIMIT 0,
    number of
    > records to
    > display
    >
    > The error message I get is:
    >
    > 'Syntax error (missing operator) in query expression
    RAND() LIMIT 0'
    >
    > If I alter 'RAND()' to 'RND()', I still get the error.
    If I remove the '0'
    > I
    > still get the error.
    >
    > Any ideas how to make this work?
    >
    > I'm using Access BTW.
    >
    > Regards
    >
    > Martin
    >

  • Display random records

    Hi guys,
    Is there an easy way to display a random record from an XML
    file? Current code:
    HEAD
    <script type="text/javascript">
    <!--
    var dsPower = new Spry.Data.XMLDataSet("broadband.xml",
    "software/product");
    //-->
    </script>
    BODY
    <div spry:region="dsPower">{product_name}</div>
    What i want to happen is when the page is loaded (and/or
    reloaded) i want the {product_name} to randomly display any one of
    my ten product names. I presume it requires use of {ds_RowID} and
    some JavaScript, but am unsure of where to begin.
    Thanks in advance for any help.

    nevermind people, i figured it out already. please close this topic.

  • How can I select the random records in u201Cstep loopu201D.

    Hi, Experts,
    I am using step loop to display the data on screen now I want to select the random records from this step loop display. Like 1st 3rd or 5th record, is there any way to select the records,
    like I did in Table control there was a filed in internal table named marked char length 1, I gave this field name in u201Cw/ SelColumnu201D it fill that field with u2018Xu2019 from where I can get the info about the selected records, in this way I can easily perform the operation on that internal table with the help of that marked field.
    Is there any way to select the records in step loop too ?
    Kind Regards,
    Faisal

    thanks for replay shwetali,
    but i just gave you example of random records with 1st 3rd and 5th my goal is not select only these records. i want to select the random mean any records from the step loop display.
    like we can select from the table control. and when select any record it place 'X' in the given internal table field.
    Thanks and kind Regards,
    Faisal

  • Dynamic Table with Random Records

    What I am trying to do is select random records from a table
    and display them in a dynamic table with max columns set to 3 and
    the 4th record to be on a new row. Below is what I have right now
    and it works to randomly pick records but has no function to set
    columns in a table. If there is an easier way feel free to let me
    know. I have tried various ways to do this but none seem to work.
    <CFQUERY NAME="getItems" DATASOURCE="absi">
    SELECT catfit.*, modcats.*, prodmat.*, prod.* FROM catfit,
    modcats,
    prodmat, prod WHERE prodmat.prodid=catfit.prodid And
    catfit.catid=modcats.catid
    ORDER BY modl ASC </cfquery>
    <cfif getItems.recordCount>
    <cfset showNum = 3>
    <cfif showNum gt getItems.recordCount>
    <cfset showNum = getItems.recordCount>
    </cfif>
    <cfset itemList = "">
    <cfloop from="1" to="#getItems.recordCount#"
    index="i">
    <cfset itemList = ListAppend(itemList, i)>
    </cfloop>
    <cfset randomItems = "">
    <cfset itemCount = ListLen(itemList)>
    <cfloop from="1" to="#itemCount#" index="i">
    <cfset random = ListGetAt(itemList, RandRange(1,
    itemCount))>
    <cfset randomItems = ListAppend(randomItems, random)>
    <cfset itemList = ListDeleteAt(itemList,
    ListFind(itemList, random))>
    <cfset itemCount = ListLen(itemList)>
    </cfloop>
    <cfloop from="1" to="#showNum#" index="i">
    <cfoutput>
    <table width="205" border="0" align="left"
    cellpadding="0" cellspacing="0">
    <tr>
    <td width="235" height="116"> <div
    align="center"><img
    src="../Products/ProductPictures/#getitems.pic[ListGetAt(randomItems,
    i)]#" width="100"></div></td>
    </tr>
    <tr>
    <td
    class="ProdTitle">#getitems.brand[ListGetAt(randomItems,
    i)]# #getitems.modl[ListGetAt(randomItems, i)]#</td>
    </tr>
    <tr>
    <td
    class="paragraph">$#getitems.prc[ListGetAt(randomItems,
    i)]#</td>
    </tr>
    <tr>
    <td><A
    href="../Products/details.cfm?prodid=#getItems.prodid[ListGetAt(randomItems,
    i)]#" class="linkcontact">more
    info</a></td>
    </tr>
    <tr>
    <td> </td>
    </tr>
    </table>
    </cfoutput>
    </cfloop>
    </cfif>

    To start a new row after 3 records, do something like this.
    <table>
    <tr>
    <cfoutput query="something">
    <td>#data#<td>
    <cfif currentrow mod 3 is 0>
    </tr><tr>
    </cfoutput>
    </tr>
    </table>
    You should also know that your approach is very inefficient
    in that you are bringing in to cold fusion more data than you need.
    First of all you are selecting every field from 3 tables when you
    don't appear to be using all of them. Second, you are selecting
    every record and you only want to use 3. There are better ways out
    there, but they are db specific and you did not say what you are
    using.

  • Random record return

    I have a DB of sites that I need to query and pull in 5
    records that are to be displayed in a random order.
    I can limit the records but I'm struggling with displaying
    them in a random order.
    Any ideas?

    We're using MySQL as the DB and to clarify I need to pull in
    5 random records in a random order.
    I've just been emailed the answer by a friend so I'llpost it
    up here.
    "SELECT *
    FROM tablename
    WHERE somefield='something'
    ORDER BY RAND() LIMIT 5"
    Seems to work fine to me.

  • Random record for ASP

    I would like to have a section on my ASP page to generate a
    random record that pulls from my database. So that each time the
    page is opened/refreshed, a different record is displayed.
    Any ideas?

    "Biggest Dave" <[email protected]> wrote in
    message
    news:e2nn6n$83e$[email protected]..
    >I would like to have a section on my ASP page to generate
    a random record
    >that pulls from my database. So that each time the page
    is
    >opened/refreshed, a different record is displayed.
    >
    > Any ideas?
    Yes.
    Of course, since I don't know what database you're using, any
    or all of
    those ideas could be useless.

  • Random Record + Update

    Looking to create a random record repeat region where the
    random records being pulled updates a hit count. i.e. a simple
    banner rotator that counts how many times it's displayed. not all
    banners being rotated are in one folder... they are simply accounts
    designated as being featured. I tried the order by rand() limit
    5... error. changed to just rand() and that worked... but how do I
    update a file based on that?

    darrel wrote:
    >> i tried the code you provided, the 2 question
    marks... but that didn't seem
    >> to do it either. anyone else have any ideas on how
    to update a hit counter
    >> based on the random record recordset?
    >
    > Instead of being a smart-***, how about actually either
    a) quoting the
    > original question or b) repeating the question.
    >
    > Anyone that's going to be of any help to you uses the
    newsgroup interface,
    > not the crappy web forum, so when you reply to a
    question that's several
    > weeks/months old, we don't see the original post.
    >
    > So, as such, all we saw was your silly question mark.
    I use a newsreader and saw the entire thread as if it was a
    new one.
    There was 3 days between the original posts and his question
    mark. Maybe
    a question mark wasn't the right way to get more attention to
    the post...
    Steve

  • Change number of record displayed for a single item alone

    Hi,
    I have a single data block with few items. Is it possible to make one item in the block as non-database item and make the display of record in the item alone to show multiple lines.
    i.e. All other items in the Data block shows single record, whereas this particular item should shows 10 records.
    Is this achievable?
    Or should i have to put that item in a separate data block and choose the data block property to "Number of records displayed" as 10?
    Thanks,
    Yuvaraaj.

    983448 wrote:
    Hi,
    I have a single data block with few items. Is it possible to make one item in the block as non-database item and make the display of record in the item alone to show multiple lines.
    i.e. All other items in the Data block shows single record, whereas this particular item should shows 10 records.Yes you can. But i will say re-check your design.
    Hamid
    Mark correct/helpful to help others to get right answer(s).*

  • How to set the number of records displayed at run time

    Is it possible to set the number of records displayed block property at run time? The built-in 'GET_BLOCK_PROPERTY' can retrieve the number of RECORDS_DISPLAYED. But I can't find SET_BLOCK_PROPERTY to set this property. Is there anyway I can set this property programmatically? Thanks for any suggestions!

    Bookmark Go to End
    goal: How to vary the number of records displayed in a block
    programmatically
    fact: Oracle Forms Developer
    fix:
    Block property 'Number of Records Displayed' can not be changed during runtime
    using SET_BLOCK_PROPERTY. However, it is still possible programmatically change
    the visual appearance of the form so that it creates effect of changing this
    property. To achieve such an effect follow these steps:
    1. in Forms Builder, in the multirecord block define the new set of items.
    The simplest way is to copy/paste the original item and rename created item.
    2. set properties of these new items so that they are the same as the properties
    of the original items. If these new items were copied from original items
    then properties are already the same. Modify following properties
    'Database item' on new items to value 'No'
    'Synchronize with item' to the value of the original item
    'Number of Items Displayed' to desired value.
    'Visible' to 'No'
    In other words, these new items are mirrors of original items.
    3. code event, which is meant to trigger the change in block appearance.
    This code should use SET_ITEM_PROPERTY built-in to set properties
    like 'VISIBLE', 'ENABLED', 'NAVIGABLE', 'UPDATE_ALLOWED' and others
    to desired value for items which are about to be displayed, then
    move cursor to one of these just displayed items with GO_ITEM built-in
    and then hide the previously displayed items.
    Example:
    Assume that the block is built on SCOTT.DEPT schema. Following will
    change the set of displayed items
    set_item_property('dept.mdeptno',visible,property_true);
    set_item_property('dept.mdname',visible,property_true);
    set_item_property('dept.mloc',visible,property_true);
    set_item_property('dept.mdeptno',enabled,property_true);
    set_item_property('dept.mdname',enabled,property_true);
    set_item_property('dept.mloc',enabled,property_true);
    set_item_property('dept.mdeptno',update_allowed,property_true);
    set_item_property('dept.mdname',update_allowed,property_true);
    set_item_property('dept.mloc',update_allowed,property_true);
    set_item_property('dept.mdeptno',navigable,property_true);
    set_item_property('dept.mdname',navigable,property_true);
    set_item_property('dept.mloc',navigable,property_true);
    go_item('dept.mdeptno');
    set_item_property('dept.deptno',visible,property_false);
    set_item_property('dept.dname',visible,property_false);
    set_item_property('dept.loc',visible,property_false);
    Regards,
    Monica

  • Rows Per Page doesn't affect the number of records displayed

    I just updated from 3.2 to 4.0 this morning. When I change the Rows Per Page value in the action menu the report doesn't change and the number of records displayed stays at 10. The report has ~6000 records. I edited the report attributes and add the rows selector to the IR search bar. This doesn't change the behavior either. I noticed that if I change the rows per page in the action menu then the drop down select list is updated, but the report still doesn't change from 10. I tried paging to the next set of results and it still remains at 10.
    Has anyone else experienced this problem?
    Tony

    Yes, Tony, I've seen this in several versions of APEX. In most cases, simply starting a new session was enough to force APEX to refresh the page and grab the new set of pagination directives. If that doesn't work, please give more info like: what type of report you are doing and what the Pagination values are. Please note the following:
    Report Template
    Pagination Scheme
    Enable Partial Page Refresh
    Display Position
    Number of Rows/Number of Rows Item
    Maximum Row Count

  • Populate multi record display item

    Hellou gurus!
    I have forms 10g and i need to populate display item in enter query mode. My problem is that I have table T1 with some static values. Table T2 is through ID connected (reference) to table T1 1:1 cardinality and T2 table also have reference to T3 table.
    I have block B2 based on table T2 and in this block I have multirecord item for inserting and updating new values for T2, but in this block ii also have no DB, multi record display item (because i don't want to allow editting in T1 table records) for diplaying static values for table T1. I want to display all static values from T1 next to the editable values in T2 (T2 multi record field is not insert yet). I tried for loop, select into but it not work. T1 values need to be selected before I started to inserting values into T2 items, but off course they need to be referenced It is hard to explain but i belive you understand.
    Can you help me how I can populate multi record item??

    You have to write the code again for your second list item....
    group_id RecordGroup;
    list_id Item  := Find_Item('button.tyear');
    list_id1 Item  := Find_Item('button.tperiod');
    status NUMBER;
    rg_name varchar2(40) := 'recgroup';
    BEGIN
    ----------------------------- LIST
    clear_list(list_id);
    group_id := Find_Group(rg_name);
    IF NOT id_null(group_id) then
        Delete_Group(group_id);
    End if;
    group_id := Create_Group_From_Query(rg_name,
    'select vm_year, vm_year from fwqgl.vouchermaster
    group by vm_year');
    status := Populate_Group(rg_name);
    Populate_List(list_id, group_id);
    /* --------------------SECOND LIST ITEM...BUT REC. GRP NAME CAN BE SAME,better to use another name if you need to retrieve list and store qry..other wise the fol. code is enuf-----------------------*/
    clear_list(list_id1);
    group_id := Find_Group(rg_name);
    IF NOT id_null(group_id) then
        Delete_Group(group_id);
    End if;
    group_id := Create_Group_From_Query(rg_name,
    'select vm_period, vm_period from fwqgl.vouchermaster
    group by vm_period');
    status := Populate_Group(rg_name);
    Populate_List(list_id1, group_id);
    END;Edited by: Dora on Dec 5, 2009 10:41 AM

  • Select Random Records with Group By?

    Hi,
    I currently select random records by using this type of SQL:
    (SELECT *
    FROM ( SELECT *
    FROM ( SELECT *
    FROM TABLEA
    ORDER BY dbms_random.value
    WHERE ROWNUM <= 100
    Based on the following data, I now want to still pick out random records but I only want 1 record from the same ID and START_DATE but where the FLAG could be Y or N.
    So with grouping by ID and START_DATE, I need to still be able to choose the record if it has anything from 1 entry or 10 entries per ID and START_DATE.
    Could this be performed with a GROUP BY?
    ID START_DATE FLAG
    1 12/12/2005 Y
    1 12/12/2005 N
    1 12/12/2005 N
    1 30/12/2005 Y
    1 30/12/2005 N
    1 30/12/2005 N
    2 10/10/2005 Y
    2 07/07/2005 Y
    Thanks for any help.
    Daniel

    Try this [not tested]:
    SELECT *
         FROM
              (SELECT *
                   FROM
                   ( SELECT
                              ID
                             ,START_DATE
                             ,FLAG
                             ,ROW_NUMBER() OVER
                                  (PARTITION BY ID,START_DATE ORDER BY dbms_random.value) RN
                        FROM TABLEA
                   ORDER BY dbms_random.value
         WHERE RN = 1
              AND ROWNUM <= 100
         ;

  • Number of items/records display

    I want to set the number of items/records display base on query. I tried Set_Block_Property and Set_Item_Property, they don't have any option for me to set it dynamically. Any ideas?
    Thanks

    A couple:
    a) Set QUERY ALL RECORDS to YES, and programmaticaly set MAXIMUM RECORDS FETCHED.
    b) in a POST-QUERY block-level trigger, check the :system.trigger_record. When it reaches the number you want, issue an ABORT_QUERY built-in.
    Hope this helps,
    Pedro

Maybe you are looking for

  • WebLogic Error : Registered more than one instance with the same objectName

    HI there, I'm facing a big problem. I have two environments installed on the same physical machine. I have ALSB and WLI servers running out there. Environment 1 - WLI port running at 7011 domain name : stp_wli_domain and ALSB port running at 8011 dom

  • Printer Going OFFLINE on Every Boot.

    Hello, In My Network 7 PCS are connected to one HP Printer(Laserjet 1020). in that 1 PC having problem is "Printer Going OFFLINE on Every Boot" then We connected on every boot/Restart  and I Restart The Servieces also like(print spoller etc..)The PC.

  • Anyone else experience these boundaries to productivity and learning in iOS 8.1.1?

    I have an iPad Air (wifi only) and iPhone 5s. I'm wondering if the following features exist in iOS 8.1.1 and maybe I've missed it? #1- Raise to speak for Siri. I know there is "Hey Siri" but in order to use that it requires you to be a wall-hugger. I

  • MacBook Pro dont wake up properly

    I have activated hot corner on my Macbook Pro 17" when I leave my desk for a short time I bring the mouse on hot corner and it goes to sleep. Some time when I move my mouse screen will be lightened and mouse will be visible but login screen wont come

  • Installing the jdbc drivers

    Hello Guys: I am new to Oracle Application DBA stuff and here is what I have to do now. I need to install the jdbc drivers in our oracle financials UAT. Here is what I heard from our Oracle support: ANSWER ====== The Patch #4159795 status is Deleted,