Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

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

Posts: 726
Name: John
Location: United States of America, California
Trades: 0
I want to make a script similar to http://whatthephoto.com/, but without duplicate photos because his site does that alot.
__________________
Free $1 gift card when you signup at
Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

goheadtry is offline
Reply With Quote
View Public Profile Visit goheadtry's homepage!
 
 
Register now for full access!
Old 05-18-2008, 10:54 AM Re: How do I show a random photowithout duplicates
rogem002's Avatar
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
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).
__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE

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

Posts: 726
Name: John
Location: United States of America, California
Trades: 0
Wait!, what if I want users to upload the photo and write to mysql though?
__________________
Free $1 gift card when you signup at
Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

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 Search this Thread
Search this Thread:

Advanced Search

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 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.52477 seconds with 12 queries