NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page Randomize code?

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

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 09-18-2005, 03:39 PM THREAD STARTER               #1 (permalink)
New Member
 
I, Brian's Avatar
Join Date: Sep 2005
Posts: 7
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 -->

????: NamePros.com http://www.namepros.com/programming/124811-randomize-code.html
How would I randomise with a script within the body itself?

Many thanks for any replies.
I, Brian is offline  
Old 09-18-2005, 06:08 PM   #2 (permalink)
Senior Member
 
nasaboy007's Avatar
Join Date: Jul 2005
Location: NJ
Posts: 1,219
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 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, 06:44 PM   #3 (permalink)
Domains my Dominion
 
sdsinc's Avatar
Join Date: Aug 2005
Location: Web 1.0
Posts: 9,552
sdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatness
 


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 Animal Rescue Wildlife
That's it rand() should do the trick.
I would do something like... (untested)
????: NamePros.com http://www.namepros.com/showthread.php?t=124811
PHP Code:
<!-- site content above --> 
<?PHP include("/home/user/public_html/section".rand(1,5).".php"); ?> 
<!-- footer below -->
sdsinc is offline  
Old 09-19-2005, 04:51 AM THREAD STARTER               #4 (permalink)
New Member
 
I, Brian's Avatar
Join Date: Sep 2005
Posts: 7
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, 06:01 AM   #5 (permalink)
Senior Member
 
dgaussin's Avatar
Join Date: May 2004
Location: France
Posts: 1,226
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 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($inputsizeof($input)) as $i) {
            include(
"/home/user/public_html/".$input[$i]); 
????: NamePros.com http://www.namepros.com/showthread.php?t=124811
}
?>
dgaussin is offline  
Old 09-20-2005, 02:03 PM THREAD STARTER               #6 (permalink)
New Member
 
I, Brian's Avatar
Join Date: Sep 2005
Posts: 7
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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Various names - AngloSaxons.info... Catsse Domains For Sale - Make Offer 0 09-14-2005 06:49 PM
2 Huge Name Forsale Vegas Entertainment Domains For Sale - Make Offer 9 09-21-2004 03:37 PM
CorePimps Code Is For Sale! contemptx For Sale / Advertising Board 2 07-20-2004 10:24 AM
Free Source Code Protector! getthis For Sale / Advertising Board 7 05-10-2004 04:14 PM

Liquid Web Smart Servers  
All times are GMT -7. The time now is 11:34 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger