Hi there,
I have i site with photo-albums on it.
to create a new album all i do is create a new
folder. I use the following code.
My only question is, how can i randomize the output,
so the order of the folders is different every time?
++++++++++++++++++++++++++++++++++++++++++++++++++ ++
function CreateFolders()
{
$the_array = Array();
$handle = opendir('.');
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != ".." && $file != "index.php") {
$the_array[] = $file;
}
}
closedir($handle);
foreach ($the_array as $PicFolder) {
echo 'table with clickable 1st thumb'
};
++++++++++++++++++++++++++++++++++++++++++++++++++ ++
I guess it's easy, but since i'm a newbie, i don't know
how to get it to work..
Any help would be greatly appreciated.
greetings knoak 8 1880
"knoak" <kn******@hotmail.com> wrote in message
news:a5**************************@posting.google.c om... Hi there,
I have i site with photo-albums on it. to create a new album all i do is create a new folder. I use the following code. My only question is, how can i randomize the output, so the order of the folders is different every time?
++++++++++++++++++++++++++++++++++++++++++++++++++ ++
function CreateFolders() { $the_array = Array(); $handle = opendir('.');
while (false !== ($file = readdir($handle))) { if ($file != "." && $file != ".." && $file != "index.php") { $the_array[] = $file; } }
closedir($handle);
foreach ($the_array as $PicFolder) { echo 'table with clickable 1st thumb' };
++++++++++++++++++++++++++++++++++++++++++++++++++ ++
I guess it's easy, but since i'm a newbie, i don't know how to get it to work..
Any help would be greatly appreciated.
greetings knoak
Try
$rand_dir=$the_array[rand() % count(the_array)];
Garp
On 31 May 2004 08:22:34 -0700, kn******@hotmail.com (knoak) wrote: I have i site with photo-albums on it. to create a new album all i do is create a new folder. I use the following code. My only question is, how can i randomize the output, so the order of the folders is different every time?
+++++++++++++++++++++++++++++++++++++++++++++++++ +++
function CreateFolders() { $the_array = Array(); $handle = opendir('.');
while (false !== ($file = readdir($handle))) { if ($file != "." && $file != ".." && $file != "index.php") { $the_array[] = $file; } }
foreach ($the_array as $PicFolder) {
foreach (shuffle($the_array) as $PicFolder) {
--
Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space
knoak wrote: My only question is, how can i randomize the output, so the order of the folders is different every time?
++++++++++++++++++++++++++++++++++++++++++++++++++ ++
function CreateFolders() { $the_array = Array(); $handle = opendir('.');
while (false !== ($file = readdir($handle))) { if ($file != "." && $file != ".." && $file != "index.php") { $the_array[] = $file;
# try this instead
$the_array[] = array(rand(), $file);
} }
closedir($handle);
# then reorder the array (randomnly)
sort($the_array);
foreach ($the_array as $PicFolder) {
# don't forget to use $PicFolder[1] for the $file part
# of the array $the_array
echo 'table with clickable 1st thumb' };
++++++++++++++++++++++++++++++++++++++++++++++++++ ++
Happy Coding :-)
--
USENET would be a better place if everybody read: : mail address : http://www.catb.org/~esr/faqs/smart-questions.html : is valid for : http://www.netmeister.org/news/learn2quote2.html : "text/plain" : http://www.expita.com/nomime.html : to 10K bytes :
Hmm. i'm sorry guys,
But i still can't get it to work...
Can someone please give me a ready example
how to read a dir, randomize the output,
and then echo the file names or so?
Thanks for the reply!!
Greetings
On 2 Jun 2004 13:00:26 -0700, kn******@hotmail.com (knoak) wrote: Hmm. i'm sorry guys,
But i still can't get it to work...
Can someone please give me a ready example how to read a dir, randomize the output, and then echo the file names or so?
Immediately after your
closedir($handle);
put:
shuffle($the_array);
--
Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space
Well,
It works perfetct!
Thanks a lot.
Greetings This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Fieldmedic |
last post by:
I'm trying to determine the best way to randomize a set of array items. I'm
thinking that I could use an arraylist and have it use the lower and upper
bounds as the limits. Any suggestions?
...
|
by: Gaffer |
last post by:
Hello
Is there a way in which I can make certain parts of Html on my website
random so that each viewer will see different material if they refresh the
page or come back onto the website later?...
|
by: Ellen Manning |
last post by:
I've got an A2K database with a report that generates any number of
random medical record numbers. The user inputs how many numbers they
want and report uses the Randomizer function found on "The...
|
by: Mr. x |
last post by:
Hello,
randomize is a function in vbscript.
What is the function for vb ?
(I have tried to use that command in the script in web-service of .net,
which used VB and not VBScript).
Thanks :)
|
by: Rich |
last post by:
Here is what I am trying for randomizing 2 numbers in the same subroutine so
that they are not equal to each other:
Dim j As Integer, k As Integer
j = New System.Random().Next(0, 10)
k = New...
|
by: Arnold |
last post by:
Hi there,
Here's the situation--there is a text field in a form in which students
will key in data. On the keypress event, I'd like for different sounds
to be played for each character typed,...
|
by: Badass Scotsman |
last post by:
Hello,
This code is supposed to generate a random string each run, however I have
had it live on a few sites, and it seems to create repeat strings all over
the place.
...
|
by: VBSTUDENT |
last post by:
I am just wondering if there is a way to randomize the aritmetic operators in code, I know how to randomize numbers but I am not sure if it is possible to randomize operators.
Any help would be...
|
by: gggram2000 |
last post by:
Hi,
I'ved spent two full days trying to find a solution, I can randomize numbers between two ranges and it works fine, But my problem is when i want to randomize five numbers that I got. eg.
I...
|
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...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
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...
|
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: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |