473,287 Members | 1,708 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

How do I retrieve items from an array in random order?

1
Hi. Can you help me please?
Is there any way to show a unique random item from an array, every time you refresh the page? In other words how do I show the items from an array in random order, one by one, by reloading the page?
Moreover the page have to be refreshed by pressing the "submit" button...

Thats what I achieved so far :) but it doesn't display the UNIQUE array item every time the page is reloaded...
as you may guess :)
Expand|Select|Wrap|Line Numbers
  1.  <html>
  2. <head><title></title></head>
  3. <body>
  4. <?php
  5. $testArray = array ("one","two","three","four","five");
  6. $number = rand(0,4);
  7. echo "$testArray[$number]";
  8. ?>
  9. <form method="post" action="test.php">
  10. <input type="submit" value="Submit">
  11. </form>
  12. </body>
  13. </html>

I'm a designer/ActionScript sort of a guy and know nothing about php,
so please don't laugh. :)
Any help is appreciated

Philip
May 10 '10 #1
2 2310
Dormilich
8,658 Expert Mod 8TB
it works as expected (at least for me), although you have to bear in mind that one out of five doesn’t give you a good distribution. it scrambled a bit better when using a larger base:
Expand|Select|Wrap|Line Numbers
  1. $number = rand(0, 100) % 5;
May 10 '10 #2
Markus
6,050 Expert 4TB
array_rand() could maybe... possibly... work for you? ;)
May 10 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Jefferis NoSpamme | last post by:
I have a query that is showing new items in a store based upon their inventory date. The problem with my Random order sort is that when the "next" link is pressed, the random function is called...
0
by: Tom | last post by:
Using AccessXP - Access2000 In my application, when an order is entered, inventory is automatically adjusted, a pull list is created, items are pulled to fill the order, and the order is...
22
by: Nhmiller | last post by:
Is there a way to do this? Thanks. Neil Cat Paintings At Carol Wilson Gallery http://www.carolwilsongallery.com
9
by: gl | last post by:
How do I take an array or arraylist, and sort it randomly? Like suppose the items in it are (1,2,3,4,5) and I want to get it to be in a random order (2,3,1,4,5). How do you do that? I think it's a...
2
by: Paul Evans | last post by:
Hi, I've created a datagrid which works fine accept the id field (the primary key field) comes out in a random order. How do I get the fields to display sequencially? Thanks for your time ...
6
by: InnoCreate | last post by:
Hi everyone. I've recently written a classic asp website which uses an MS Access datasource. I know this is less than an ideal data source as it has limited functionality. I have a search form on...
9
by: Greg Collins [Microsoft MVP] | last post by:
I've done a bit of research on this topic in the newsgroups and on MSDN, and though it sounds possible, I still don't understand how I would make it work. I want to be able to use named groups to...
4
by: kevincw01 | last post by:
Anyone have a clever way to retrieve for example, items 0-29 from an array of size N>29, in random order? The catch is that I dont want to print any items more than once and I dont want to miss...
9
by: Tuxedo | last post by:
I'd like to reorganize the third, fourth, fifth and sixth, as well as any elements thereafter in an array in random order: var a = new...
2
by: federicog | last post by:
I have to create a listing in random order from a few mysql tables. I can't use ORDER BY RAND() for a few reasons: - The random order has to change only every 24hs, ie: today it will show rows...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.