Help I NEED HELP WITH SCRIPT! (need duplicate retrieval restriction) (Read 233 times)

  • Avatar of Madolah
  • ;Wyrm
  • PipPipPipPipPip
  • Group: Global Moderator
  • Joined: Oct 4, 2005
  • Posts: 749
I'm making a small thing on www.indymix.net that retrieves 4 images from a bank folder of images. My problem is that there are duplicate returns coming up as I am retrieving 4 times with no duplicate post restriction.


here is my code for the thing.


<script type="text/javascript">
var gallery =new Array();
gallery[0] = new Array(new Array ("1.png", "#01"), new Array ("2.png", "#02"), new Array ("3.png", "#03"), new Array ("4.png", "#04"), new Array ("5.png", "#05"), new
Array ("6.png", "#06"), new Array ("7.png", "#07"), new Array ("8.png", "#08"), new Array ("9.png", "#09"), new Array ("10.png", "#10"), new Array ("11.png", "#11"));


function pickImageFrom(whichGallery)
{
var idx = Math.floor(Math.random() * gallery[whichGallery].length);


document.write('<a href="' + gallery[whichGallery][idx][1] + '"><img src="images/SCS/' + gallery[whichGallery][idx][0] + '"></a>');
}
</script>




<script language="javascript">pickImageFrom(0);</script><br />
<script language="javascript">pickImageFrom(0);</script><br />
<script language="javascript">pickImageFrom(0);</script><br />
<script language="javascript">pickImageFrom(0);</script><br />




Now how can I have it (or add something to it) to restrict the 4 retrievals from being duplicates.


Thanks Codemonkeys
Wyrm  | Madolah | ær 
  • Avatar of Biggles
  • I know your secrets
  • PipPipPipPipPip
  • Group: Premium Member
  • Joined: May 5, 2005
  • Posts: 688
remove the pic from the list after it's been picked, i guess. if i did it, i would have had a function that generates a series of such images picked from a common gallery rather than generating each picture in the document.  then again, i probably would have also done it server-side and done a number of other things differently too.
  • Avatar of Madolah
  • ;Wyrm
  • PipPipPipPipPip
  • Group: Global Moderator
  • Joined: Oct 4, 2005
  • Posts: 749
I'm open to suggestions and options. as long as  i get task at hand completed.
Wyrm  | Madolah | ær 
  • Avatar of Madolah
  • ;Wyrm
  • PipPipPipPipPip
  • Group: Global Moderator
  • Joined: Oct 4, 2005
  • Posts: 749
<script type="text/javascript">
var gallery = new Array();
gallery[0] = new Array(new Array ("1.png", "#01"), new Array ("2.png", "#02"), new Array ("3.png", "#03"), new Array ("4.png", "#04"), new Array ("5.png", "#05"), new
Array ("6.png", "#06"), new Array ("7.png", "#07"), new Array ("8.png", "#08"), new Array ("9.png", "#09"), new Array ("10.png", "#10"), new Array ("11.png", "#11"));


function pickImageFrom(whichGallery)
{
var idx = Math.floor(Math.random() * gallery[whichGallery].length);

document.write('<a href="' + gallery[whichGallery][idx][1] + '"><img src="images/SCS/' + gallery[whichGallery][idx][0] + '"></a>');
}
</script>


<script language="javascript">pickImageFrom(0);</script><br />
<script language="javascript">pickImageFrom(0);</script><br />
<script language="javascript">pickImageFrom(0);</script><br />
<script language="javascript">pickImageFrom(0);</script><br />

heres what i got, it only loads 4 images, to anchors not links and has no collision detection to stop duplicate retreivals, which would be nice.
Wyrm  | Madolah | ær 
  • Avatar of Biggles
  • I know your secrets
  • PipPipPipPipPip
  • Group: Premium Member
  • Joined: May 5, 2005
  • Posts: 688
the only thing changed between the op version and that version is the spacing is different. so do what I said to do. each time a pic is placed on the page, remove it from the list of options. or if you want a different solution, write a function that picks x random images from a list by shuffling it and then iterating through. neither of these are fast solutions for the general case, but they're easy to implement and will not cause performance problems on small lists.
  • Avatar of Madolah
  • ;Wyrm
  • PipPipPipPipPip
  • Group: Global Moderator
  • Joined: Oct 4, 2005
  • Posts: 749
Got it working after, I couldnt solve the Repeat/Duplicate retrievals from happening, but i got links to work!
Wyrm  | Madolah | ær