Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

Select 5 records at random

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Select 5 records at random

    Can someone please show either the Action Script or XBasic for the following idea:

    Select ID# and Name fields for 5 different records at random from MyTable.

    In this case, the underlying table is Access 2003.

    Thanks.

    #2
    Re: Select 5 records at random

    This may be more than you are looking for, but this is code from the home page of an A5 website. The important part is defining the search string and inserting it in the table.external_...() function. The rest of the code makes each text snippet a hyperlink and bullet text.

    For reference the code is used on this page www.alphadevnet.com where it says "Testimonials".

    HTML Code:
    <div class="adbox" style="MARGIN-TOP: 10px;">
    <h2>Client Testimonials</h2>
    <p>
    <ul>
    <%a5
    dim dta1 as c=""
    dta1 = "'<li><a href=\"dev_profile.a5w?devid='+devid+'\">'+left(Comment,90)+'...</a>'"
    srch = "random_records(5)"
    ?table.external_record_content_get("[PathAlias.ADB_Path]\dev_testimonials",dta1,"",srch)
    %>
    </ul>
    </p>
    </div>
    Steve Wood
    See my profile on IADN

    Comment


      #3
      Re: Select 5 records at random

      Thanks, Steve, but I really need the XBasic or Action Script. I'm trying to code the OnPush event for a button on a form. Perhaps I'm more confused than I realized; I thought that whether or not an app is online or desktop, the underlying code is XBasic rather than HTML. Is that correct?

      Comment


        #4
        Re: Select 5 records at random

        What I showed you is xbasic. The HTML just gives the output special formatting in the browser.

        If this is Desktop, you should post in Desktop area. The xbasic might be the same, but how you go about implementing it would be different.
        Steve Wood
        See my profile on IADN

        Comment


          #5
          Re: Select 5 records at random

          Warren,
          One of the issues is that the underlying table is in Access. So you have to get to it with AlphaDAO or else create an active link table to the Access table. The active link is probably the easiest way to go.
          Assume you have created the link as
          al_client

          Then to select a crlf()-delimited list of 5 random records with the information you want, you could write

          clientList=table.external_record_content_get("al_client",\
          "ID+':'+Name","name","random_records(5)")

          If it's a large table, though, this will be slow, because the entire table will have to be sent to the client for random_records() to work. There's no query optimization that can be run at the server end (by definition! -- you're asking for random records, and SQL doesn't support that!)
          There's a couple of solutions. I think they all depend on the assumption that the ID field has been sequentially assigned; I don't otherwise see how one can pull out a record from a table that doesn't use record numbers.
          Code:
          t=table.open("al_client")
          nrecs=t.records_get()   ' total records - a count(*) in SQL
          i=0
          dim clientList as c=""
          while i<5
            testID=ceiling(rand()*nrecs)
            testClient=t.record_content_get("al_client","ID+':'+Name",\
          "","ID="+testID)
            if testClient>"" then
              clientList=clientList+testClient+crlf()
              i=i+1
            end if
          end while
          t.close()
          ui_msg_box("Client List",clientList)
          And if that is still too slow, then you would need to use SQL queries -- but I don't know whether Access understands SQL. Does it?

          Comment


            #6
            Re: Select 5 records at random

            I don't have the xbasic because I wrote a program that did this in Foxpro. I needed to write an application that picked employees for a random drug test.

            I remember that I used the random number generator to generate a certain # of random #'s (specified by the user) based on the total amount of records in our employee file.

            I then created an array with the #'s generated and I then compared them to each other to make sure none of the #'s were the same.

            Once I was sure I had distinct #'s, I then opened the table, went to the top, and then I went to the record associated with that #.

            This worked for us. Hope this helps.
            ---------------------------------------------------
            Barry Kucher
            http://www.411tech.org

            Comment


              #7
              Re: Select 5 records at random

              I'm attempting to use the following script to obtain random results but so far it places the results in the same order. Created a grid that uses rand() and this works great but when I place it in a page, my html in the rest of the page is somehow adversely affected. I prefer the following method anyway for page load speed.

              dim tbl as P
              dim qry as P
              tbl = table.open("[pathalias.adb_path]\Advertisements")
              query.filter = "random_records(10, \"status='Active'.and.state<>''\")"
              query.order = "postnum"
              query.options = ""
              qry = tbl.query_create()
              tbl.fetch_first()
              while .not. tbl.fetch_eof()
              url = tbl.Link
              display = tbl.Title
              ? "<a href=\"" + url + "\" target=\"_blank\"><strong><font color=#0066CC face=Arial size=2><center>" + display + "</center></strong></font></a>"

              ? "<font size=2 color=#339966>"+tbl.Content+"</font><BR><BR>"
              tbl.fetch_next()
              end while
              end if
              qry.drop()
              tbl.close()
              Last edited by EricN; 01-06-2010, 02:27 PM.
              Eric

              Alpha Five Websites
              longlivepuppies.com
              socialservicenetwork.com
              -------------------------------------------------
              socialservicenetwork.org

              Comment


                #8
                Re: Select 5 records at random

                Originally posted by EricN View Post
                I'm attempting to use the following script to obtain random results but so far it places the results in the same order.
                Can you try that explanation again?

                query.order = "postnum"


                sets the order of the results. I don't see that changed anywhere so you get the same order.
                There can be only one.

                Comment


                  #9
                  Re: Select 5 records at random

                  Hello Stan,

                  I've tried query.order = "" with the same results. Maybe not. Are you saying I should have something else there?

                  This is from the help:
                  query.filter = "random_records(10, \"orderdate > {5/1/2000}\")"
                  query.order = "order_total"

                  This is what I'm attempting to accomplish. Sponsored Ads to be displayed in random order each time page is refreshed. (far left of page)
                  http://socialservicenetwork.com/JobsBrowse.a5w?
                  Last edited by EricN; 01-06-2010, 02:39 PM.
                  Eric

                  Alpha Five Websites
                  longlivepuppies.com
                  socialservicenetwork.com
                  -------------------------------------------------
                  socialservicenetwork.org

                  Comment


                    #10
                    Re: Select 5 records at random

                    Here is another way to create such a list. I left in the HTML so you can see how to include that for your output. This lists the leftmost 90 chars of the Comments field in a bulleted list.


                    dim dta1 as c=""
                    ?"<ul>"
                    dta1 = "'<li><a href=\"dev_profile.a5w?devid='+devid+'\">'+left(Comment,90)+'...</a>'"
                    srch = "random_records(5)"
                    ?table.external_record_content_get("[PathAlias.ADB_Path]\dev_testimonials",dta1,"",srch)
                    ?"</ul>"
                    Steve Wood
                    See my profile on IADN

                    Comment


                      #11
                      Re: Select 5 records at random

                      Eric,

                      Steve likely has your answer. As for the question about the query.order, I think you must understand what "random_records(10, \"orderdate > {5/1/2000}\")"
                      does.

                      Not that I know exactly but I imagine whatever algorithm is behind it has some means of selecting 5 record numbers for records where the orderdate > {2/1/2000} out of the available records. Those five records are likely reurned in record number order to the script where they can be further ordered by query.order.

                      IOW I don't imagine the random_records() function jumps around the table selecting records at random. Even if it did, query.order would rearrange them.
                      There can be only one.

                      Comment


                        #12
                        Re: Select 5 records at random

                        Thank you Stan and Steve! Here is what I did...

                        uids = table.external_record_content_get("[PathAlias.ADB_Path]\Advertisements","postnum","","random_records(6)")
                        For each y in uids
                        dim vAdLink as c = lookup("[pathalias.adb_path]\advertisements","Postnum=" + quote(y),"Link")
                        dim vTitle as c = lookup("[pathalias.adb_path]\advertisements","Postnum=" + quote(y),"Title")
                        dim vContent as c = lookup("[pathalias.adb_path]\advertisements","Postnum=" + quote(y),"Content")

                        ? "<a href=\"" + vAdLink + "\" target=\"_blank\"><strong><font color=#0066CC face=Arial size=2><center>" + vTitle + "</center></strong></font></a>"
                        ? "<font size=2 color=#339966>"+vContent+"</font><BR><BR>"
                        Next

                        I use for/next quite a bit but couldn't figure how to randomize the array. This displayed results are exactly what I desire but wondering if this is the most processor efficient method.
                        Last edited by EricN; 01-06-2010, 06:00 PM.
                        Eric

                        Alpha Five Websites
                        longlivepuppies.com
                        socialservicenetwork.com
                        -------------------------------------------------
                        socialservicenetwork.org

                        Comment


                          #13
                          Re: Select 5 records at random

                          Eric, work on the table.external_record_content_get function. You can get your entire list including HTML and multiple fields out of that one function. Right now your code requres 19 lookups to get the result. If you are going to use the lookups, use lookupC() instead which uses an index to find. Finally, if the values in any of your fields are greater than 1024, lookup() will truncate. table.external_record_content_get() does not truncate and can bring back an unlimited amount.
                          Steve Wood
                          See my profile on IADN

                          Comment


                            #14
                            Re: Select 5 records at random

                            You can get your entire list including HTML and multiple fields out of that one function.
                            Hi Steve,
                            Can you give an example?? Help only shows how you can obtain contents from one field... unless I'm missing something.

                            For now I not using dim and am using lookupc()
                            vAdLink = alltrim(lookupc("F",alltrim(y),"alltrim(link)","[pathalias.adb_path]\advertisements","postnum"))

                            Update:
                            Went back to this which works the way I want it to. I think I now understand this better Stan. :)

                            dim tbl as P
                            dim qry as P
                            tbl = table.open("[pathalias.adb_path]\advertisements")
                            query.filter = "random_records(6)"
                            query.order = ""
                            query.options = ""
                            qry = tbl.query_create()
                            tbl.fetch_first()
                            while .not. tbl.fetch_eof()
                            ? "<a href=\"" + tbl.Link + "\" target=\"_blank\"><strong><font color=#0066CC face=Arial size=2><center>" + tbl.Title + "</center></strong></font></a>"
                            ? "<font size=2 color=#339966>"+tbl.Content+"</font><BR><BR>"
                            tbl.fetch_next()
                            end while
                            qry.drop()
                            tbl.close()
                            Last edited by EricN; 01-06-2010, 06:42 PM.
                            Eric

                            Alpha Five Websites
                            longlivepuppies.com
                            socialservicenetwork.com
                            -------------------------------------------------
                            socialservicenetwork.org

                            Comment


                              #15
                              Re: Select 5 records at random

                              Here is one with a little HTML mixed in. It creates a Title and then a short_description under it in smaller font.

                              dta = "'<div class=\"adbox\" style=\"margin-left:5px\"><h3 style=\"margin-top:0;margin-bottom:2px\">'+title+'</h3><small>'+short_desc+'</small></div>'"
                              ?table.external_record_content_get("[PathAlias.ADB_Path]\event_item",dta,"sortlevel","category=\"web\"")

                              The above one is self-contained, here is a much more complex one that does require a FOR NEXT loop.


                              Code:
                              'TESTIMONIALS
                              dim dta as c
                              dta = "id+'|'+devid+'|'+Name+'|'+Company+'|'+stritran(Comment,crlf(),\"~\")+'|'+Date_Added"
                              tmp = table.external_record_content_get("[PathAlias.ADB_Path]\dev_testimonials",dta,"","devid="+quote(devid))
                              
                              if tmp <> ""
                              	lst = lst + "<div class=\"tabbertab\">"
                              	lst = lst + "<br>"
                              	lst = lst + "<h2>Testimonials</h2>"
                              	dim tlst as c = ""
                              	for each foo in tmp
                              		tlst = tlst + "<p>"
                              		tlst = tlst + "<strong>Name:</strong> " + word(foo,3,"|") + "<br>"
                              		tlst = tlst + "<strong>Company:</strong> " + word(foo,4,"|") + "<br>"
                              '		tlst = tlst + "<strong>Dated:</strong> " + word(foo,6,"|") + "<br>"
                              		tlst = tlst + "<strong>Comment:</strong> " + stritran(word(foo,5,"|"),"~","<br>")
                              		tlst = tlst + "</p>"
                              		tlst = tlst + "<hr>" + crlf()
                              	next
                              	lst = lst + tlst
                              	lst = lst + "</div><!-- TABBER -->"
                              end if
                              This produces a list like the one under the Testimonial tab on this page: http://alphadevnet.com/dev_profile.a...94e0277e3a4e7a

                              (Glad I did this, I see I have bogus content at that address on a live website.)
                              Steve Wood
                              See my profile on IADN

                              Comment

                              Working...
                              X