HeavensGirll Posted July 17, 2008 Share Posted July 17, 2008 Obviously I'm new here - and I really don't know much about PHP - so here I am. I'm trying to put together a website for the company I work for - I've got the design all finished and I downloaded a script I thought would be perfect. I'm trying to shuffle several images on one page. However the script shuffles the photos - but wont shuffle the links that go with the photos. =( Anyone know a way I can make that happen? Here's some of the code. I added the links into the index.php page - but again they stay static and the images rotate. =( <!-- copy the below code into any php file! --> <a href="http://www.p.com"><img src='rotate.php?i=0'>image #1 <a href="http://www.phone.com"><img src='rotate.php?i=1'>image #2 <a href="http://www.phe.com"><img src='rotate.php?i=2'>image #3 this snippet below is from a random.php page $images=array( // list of files to rotate - add as needed "bomb.gif", "frown.gif", "grim.gif", "smile.gif" ); [code] If someone could pretty please guide me in the right direction I would be so happy. Thanks. Charlie [/code] Link to comment https://forums.phpfreaks.com/topic/115258-need-some-help/ Share on other sites More sharing options...
Skittalz Posted July 17, 2008 Share Posted July 17, 2008 can you post all the code associated with the images please... thanks Steve Link to comment https://forums.phpfreaks.com/topic/115258-need-some-help/#findComment-592570 Share on other sites More sharing options...
discomatt Posted July 17, 2008 Share Posted July 17, 2008 This is simple enough. This is the way I'd do it <?php $images = array( 'bomb.html' => 'bomb.gif', 'frown.html' => 'frown.gif', 'somePage.html' => 'grim.gif', 'anotherPage.php' => 'smile.gif' ); # Randomize the array! key_shuffle( $images ); # Output the first ( random ) element echo '<a href="'. key( $images ) .'"><img src="'. current( $images ) .'"></a>'; function key_shuffle (&$array) { /* Auxiliary array to hold the new order */ $aux = array(); /* We work with an array of the keys */ $keys = array_keys($array); /* We shuffle the keys */ shuffle($keys); /* We iterate thru' the new order of the keys */ foreach($keys as $key) { /* We insert the key, value pair in its new order */ $aux[$key] = $array[$key]; /* We remove the element from the old array to save memory */ unset($array[$key]); } /* The auxiliary array with the new order overwrites the old variable */ $array = $aux; } ?> Link to comment https://forums.phpfreaks.com/topic/115258-need-some-help/#findComment-592578 Share on other sites More sharing options...
HeavensGirll Posted July 17, 2008 Author Share Posted July 17, 2008 Here is the whole index.php page <!-- copy the below code into any php file! --> <a href="http://www.p.com"><img src='rotate.php?i=0'>image #1 <a href="http://www.phone.com"><img src='rotate.php?i=1'>image #2 <a href="http://www.phe.com"><img src='rotate.php?i=2'>image #3 then this is the rotate php page. <?php // rotate images randomly but w/o dups on same page - format: // <img src='rotate.php?i=0'> - rotate image #0 - use 'i=1' // for second, etc // (c) 2004 David Pankhurst - use freely, but please leave in my credit $images=array( // list of files to rotate - add as needed "bomb.gif", "frown.gif", "grim.gif", "smile.gif" ); $total=count($images); $secondsFixed=10; // seconds to keep list the same $seedValue=(int)(time()/$secondsFixed); srand($seedValue); for ($i=0;$i<$total;++$i) // shuffle list 'randomly' { $r=rand(0,$total-1); $temp =$images[$i]; $images[$i]=$images[$r]; $images[$r]=$temp; } $index=(int)($_GET['i']); // image index passed in $i=$index%$total; // make sure index always in bounds $file=$images[$i]; header("Location: $file"); // and pass file reference back ?> [code] [/code] Link to comment https://forums.phpfreaks.com/topic/115258-need-some-help/#findComment-592580 Share on other sites More sharing options...
Skittalz Posted July 17, 2008 Share Posted July 17, 2008 // Creating Arrays [this should be above all your HTML code // $images=array( // list of files to rotate - add as needed "bomb.gif", "frown.gif", "grim.gif", "smile.gif" ); $links = array( // list of links to rotate - add as needed "http://www.p.com", "http://www.phone.com", "http://www.phe.com", "http://www.lol.com ); function randomize() srand(time()); return = (rand()%4)+1; // generates a random number 1-4 } function display_image($random) { //prints the image with the correct link echo "<a href=\"".$links[$random]."\"><img src=\"".$images[$random]."\"></a>"; } //Where ever you need to display a random image input -- $random = randomize(); display_image($random); Hope this helped Sorry there was a small mistake which I addressed Link to comment https://forums.phpfreaks.com/topic/115258-need-some-help/#findComment-592582 Share on other sites More sharing options...
discomatt Posted July 17, 2008 Share Posted July 17, 2008 Skittalz You may want to re-vamp it a little... you want to generate a number between 0-3 inclusively ( array keys start at 0 ) And rather than use (rand()%4)+1 You can just use rand( 0, 3 ) Or even better mt_rand( 0, 3 ) Link to comment https://forums.phpfreaks.com/topic/115258-need-some-help/#findComment-592588 Share on other sites More sharing options...
HeavensGirll Posted July 17, 2008 Author Share Posted July 17, 2008 In your sample does the list that the photos go in and the list that the links go in match each other? For instance you.html goes with you.gif in the 3rd line in each section? And so on? Mucho Gracias Charlie Link to comment https://forums.phpfreaks.com/topic/115258-need-some-help/#findComment-592590 Share on other sites More sharing options...
discomatt Posted July 17, 2008 Share Posted July 17, 2008 Both of our examples accomplish this... try them out Link to comment https://forums.phpfreaks.com/topic/115258-need-some-help/#findComment-592597 Share on other sites More sharing options...
HeavensGirll Posted July 17, 2008 Author Share Posted July 17, 2008 So you guys know this is hard for me to comprehend here lol. You confused me when you said it goes above all the html. Does that mean it goes in the php rotate page? And then I keep the index.php page how it is with this code below? <!-- copy the below code into any php file! --> <img src='rotate.php?i=0'>image #1 <img src='rotate.php?i=1'>image #2 <img src='rotate.php?i=2'>image #3 then in the rotate php I'm going to put $images=array( // list of files to rotate - add as needed "bomb.gif", "frown.gif", "grim.gif", "smile.gif" ); $links = array( // list of links to rotate - add as needed "http://www.p.com", "http://www.phone.com", "http://www.phe.com", "http://www.lol.com ); function randomize() srand(time()); return = (rand()%4)+1; // generates a random number 1-4 } function display_image($random) { //prints the image with the correct link echo "<a href=\"".$links[$random]."\"><img src=\"".$images[$random]."\"></a>"; } //Where ever you need to display a random image input -- $random = randomize(); display_image($random); between the php code? I'm sorry I'm getting confused. Link to comment https://forums.phpfreaks.com/topic/115258-need-some-help/#findComment-592606 Share on other sites More sharing options...
HeavensGirll Posted July 17, 2008 Author Share Posted July 17, 2008 Wait - so I don't need the rotate.php page at all with what you gave me right? This all just goes into the html? I just have to put the correct path to the images? And they have to be equal with the links? Link to comment https://forums.phpfreaks.com/topic/115258-need-some-help/#findComment-592607 Share on other sites More sharing options...
discomatt Posted July 17, 2008 Share Posted July 17, 2008 You got it It's too simple to have in an outside script Link to comment https://forums.phpfreaks.com/topic/115258-need-some-help/#findComment-592613 Share on other sites More sharing options...
HeavensGirll Posted July 17, 2008 Author Share Posted July 17, 2008 You might have just made my day. One other question though. I want to have 5 images across the screen and unlimited up and down. So I may have 10 rows of 5 across. Would I just make a table and put the part of the code you told me to put where I want each picture to appear in it's own table or is there an easier way? Give me long enough and I just might confuse you! Link to comment https://forums.phpfreaks.com/topic/115258-need-some-help/#findComment-592617 Share on other sites More sharing options...
discomatt Posted July 17, 2008 Share Posted July 17, 2008 This gets bit trickier, cause you have to loop through images, then check to see if you've looped through 5, insert a linebreak if you have, and continue... Give it a shot and post up an attempt, and I'll help you from there Link to comment https://forums.phpfreaks.com/topic/115258-need-some-help/#findComment-592628 Share on other sites More sharing options...
HeavensGirll Posted July 17, 2008 Author Share Posted July 17, 2008 Okay - I'm gonna work on it now and see if I can make it happen. =) Link to comment https://forums.phpfreaks.com/topic/115258-need-some-help/#findComment-592640 Share on other sites More sharing options...
discomatt Posted July 17, 2008 Share Posted July 17, 2008 If you get stuck on something small you can bug me via msn - mmatt300 [at] hotmail [dot] com Link to comment https://forums.phpfreaks.com/topic/115258-need-some-help/#findComment-592642 Share on other sites More sharing options...
darkfreaks Posted July 17, 2008 Share Posted July 17, 2008 or you can bug me my email is on my profile Link to comment https://forums.phpfreaks.com/topic/115258-need-some-help/#findComment-592645 Share on other sites More sharing options...
Skittalz Posted July 17, 2008 Share Posted July 17, 2008 This should create that table $COL = 10; // Number of cols $ROW = 5; // Number of rows echo "<table>"; for($y = 0; $y < $COL; $y++) { echo "<tr>"; for($x = 0; $x < $ROW; $x++) { $random = randomize(); echo "<td>"; display_image($random); echo "</td>"; } echo "</tr>"; } echo "</table>"; since everyone is displayin their email i might as well to skittalz_sbrown at hotmail dot com Link to comment https://forums.phpfreaks.com/topic/115258-need-some-help/#findComment-592660 Share on other sites More sharing options...
discomatt Posted July 17, 2008 Share Posted July 17, 2008 Your code is incomplete. What if there are only, say 23 images to display? Link to comment https://forums.phpfreaks.com/topic/115258-need-some-help/#findComment-592665 Share on other sites More sharing options...
Skittalz Posted July 17, 2008 Share Posted July 17, 2008 It doesn't display a set amount of images.... It displays images choosen from random so there could be repeats Link to comment https://forums.phpfreaks.com/topic/115258-need-some-help/#findComment-592666 Share on other sites More sharing options...
HeavensGirll Posted July 17, 2008 Author Share Posted July 17, 2008 I don't have MSN but I'm sending you an e-mail. Coming from my user name plus aol dot com. =) Link to comment https://forums.phpfreaks.com/topic/115258-need-some-help/#findComment-592681 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.