[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.


Closed Thread
 
LinkBack Thread Tools
Old 09-18-2005, 02:39 PM   #1 (permalink)
New Member
 
I, Brian's Avatar
 
Join Date: Sep 2005
Posts: 7
6.00 NP$ (Donate)

I, Brian is an unknown quantity at this point


Randomize code?

Sorry to ask a simple question, but I'm looking to randomise a display of content, which are called up with basic PHP include files.

So if there are 5 images, I'm calling them up as:

Code:
<!-- site content above --> 
<?PHP include("/home/user/public_html/section1.php"); ?> 
<?PHP include("/home/user/public_html/section2.php"); ?> 
<?PHP include("/home/user/public_html/section3.php"); ?> 
<?PHP include("/home/user/public_html/section4.php"); ?> 
<?PHP include("/home/user/public_html/section5.php"); ?>
<!-- footer below -->

How would I randomise with a script within the body itself?

Many thanks for any replies.
I, Brian is offline  
Old 09-18-2005, 05:08 PM   #2 (permalink)
Senior Member
 
nasaboy007's Avatar
 
Join Date: Jul 2005
Location: NJ
Posts: 1,112
1,454.30 NP$ (Donate)

nasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud of


do you want to randomize the section1, section2, section3, etc?

or do you want to randomize something INSIDE section1, section2, etc?

here's a link to the php random manual anyway: http://us3.php.net/rand
nasaboy007 is offline  
Old 09-18-2005, 05:44 PM   #3 (permalink)
Domains my Dominion
 
sdsinc's Avatar
 
Join Date: Aug 2005
Location: Web 1.0
Posts: 6,285
1,095.94 NP$ (Donate)

sdsinc has a reputation beyond reputesdsinc has a reputation beyond reputesdsinc has a reputation beyond reputesdsinc has a reputation beyond reputesdsinc has a reputation beyond reputesdsinc has a reputation beyond reputesdsinc has a reputation beyond reputesdsinc has a reputation beyond reputesdsinc has a reputation beyond reputesdsinc has a reputation beyond reputesdsinc has a reputation beyond repute

Third World Education Find Marrow Donors! Find Marrow Donors! Find Marrow Donors! Find Marrow Donors! Animal Rescue Animal Cruelty AIDS/HIV Animal Rescue Wildlife Breast Cancer
That's it rand() should do the trick.
I would do something like... (untested)
PHP Code:
<!-- site content above -->
<?PHP include("/home/user/public_html/section".rand(1,5).".php"); ?>
<!-- footer below -->
sdsinc is online now  
Old 09-19-2005, 03:51 AM   #4 (permalink)
New Member
 
I, Brian's Avatar
 
Join Date: Sep 2005
Posts: 7
6.00 NP$ (Donate)

I, Brian is an unknown quantity at this point


The trouble is trying to get the files 1-5 to be returned in a random order -

ie,

page load: file 5, file 3, file 1, file 4, file 2
refresh: file 3, file 2, file 5, file 1, file 4
refresh again: file 2, file 4, file 1, file 3, file 5
I, Brian is offline  
Old 09-19-2005, 05:01 AM   #5 (permalink)
Senior Member
 
dgaussin's Avatar
 
Join Date: May 2004
Location: France
Posts: 1,294
85.60 NP$ (Donate)

dgaussin is a splendid one to beholddgaussin is a splendid one to beholddgaussin is a splendid one to beholddgaussin is a splendid one to beholddgaussin is a splendid one to beholddgaussin is a splendid one to beholddgaussin is a splendid one to behold


Something like that maybe...

PHP Code:
<?php
srand
((float) microtime() * 10000000);
$input = array("section1.php", "section2.php", "section3.php", "section4.php", "section5.php");
//$input = array_rand($input, sizeof($input));
foreach (array_rand($input, sizeof($input)) as $i) {
            include(
"/home/user/public_html/".$input[$i]);
}
?>
dgaussin is offline  
Old 09-20-2005, 01:03 PM   #6 (permalink)
New Member
 
I, Brian's Avatar
 
Join Date: Sep 2005
Posts: 7
6.00 NP$ (Donate)

I, Brian is an unknown quantity at this point


That worked dgaussin - many thanks for that.
I, Brian is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
CorePimps Code Is For Sale! contemptx For Sale / Advertising Board 2 07-20-2004 09:24 AM
Free Source Code Protector! getthis For Sale / Advertising Board 7 05-10-2004 03:14 PM

Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 04:08 AM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85