Reply
How do I show a random photowithout duplicates
Old 05-17-2008, 05:58 PM How do I show a random photowithout duplicates
goheadtry's Avatar
Webmaster Talker

Posts: 715
Name: John
Location: United States of America, California
I want to make a script similar to http://whatthephoto.com/, but without duplicate photos because his site does that alot.
goheadtry is offline
Reply With Quote
View Public Profile Visit goheadtry's homepage!
 
When You Register, These Ads Go Away!
Old 05-18-2008, 09:54 AM Re: How do I show a random photowithout duplicates
rogem002's Avatar
Webmaster Talker

Posts: 607
Name: Mike
Location: United Kingdom
Do something like below:
PHP Code:
<?php # Random method.
// Start the sessions
session_start();

// Give each picture a number.
$picture[1] = "http://www.example.com/picture1.png";
$picture[2] = "http://www.example.com/picture2.png";
$picture[3] = "http://www.example.com/picture3.png";

// Let set some variables.
$maxnumber count($picture); // Count how many there are in the array,

// Pick a random number between these:
$random_number rand  (1,$maxnumber); // This will pick a number between 1 and 3.

// Now lets check it was not the last picture used:
if($random_number == $_SESSION['lastrandomnumber']){ // It's the same as the last number.
    
if($random_number == $maxnumber){ // if it's the 4.
        
$random_number $random_number 1;
    } else { 
// otherwise show the nest one.
        
$random_number $random_number 1;
    }
}

// Then show that picture
echo $picture[$random_number];

// Now lets update the session:
$_SESSION['lastrandomnumber'] = $random_number

?>
Of course, this is a simplified version. Using the session thing you could probably store what has been already scene. You would also need to take out the randomness

On the other hand, you could use this:

PHP Code:
<?php # Add one method.
// Start the sessions
session_start();

// Give each picture a number.
$picture[1] = "http://www.example.com/picture1.png";
$picture[2] = "http://www.example.com/picture2.png";
$picture[3] = "http://www.example.com/picture3.png";

// Let set some variables.
$maxnumber count($picture); // Count how many there are in the array,
$next_picture $_SESSION['lastrandomnumber'] + 1// what the next picture is.

// Pick a random number between these:
if($next_picture == $maxnumber){
$next_picture 0// Back to beginning.
}


// Then show that picture
echo $picture[$next_picture];

// Now lets update the session:
$_SESSION['lastrandomnumber'] = $next_picture

?>
Again, this method is not perfect (they will always start from 0).
__________________
Website Services
PHP Code:
if(Added_Talkupation($post) == TRUE){iHug($you);} 

Last edited by rogem002 : 05-18-2008 at 10:44 AM.
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Old 05-18-2008, 03:54 PM Re: How do I show a random photowithout duplicates
goheadtry's Avatar
Webmaster Talker

Posts: 715
Name: John
Location: United States of America, California
Wait!, what if I want users to upload the photo and write to mysql though?
goheadtry is offline
Reply With Quote
View Public Profile Visit goheadtry's homepage!
 
Reply     « Reply to How do I show a random photowithout duplicates
 

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

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




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.14138 seconds with 12 queries