Jump to content


Photo

I NEED HELP WITH SCRIPT! (need duplicate retrieval restriction)


  • Please log in to reply
5 replies to this topic

#1 Madolah

Madolah

    ;Wyrm

  • Salty Members
  • 2035 posts
  • LocationSt.John's , Newfoundland, Canada

Posted 01 March 2012 - 09:33 AM

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 


#2 Biggles

Biggles

    Advanced Member

  • Salty Members
  • 984 posts
  • LocationNew Zealand

Posted 02 March 2012 - 07:05 AM

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.

#3 Madolah

Madolah

    ;Wyrm

  • Salty Members
  • 2035 posts
  • LocationSt.John's , Newfoundland, Canada

Posted 02 March 2012 - 08:20 AM

I'm open to suggestions and options. as long as  i get task at hand completed.

Wyrm  | Madolah | ær 


#4 Madolah

Madolah

    ;Wyrm

  • Salty Members
  • 2035 posts
  • LocationSt.John's , Newfoundland, Canada

Posted 03 March 2012 - 12:01 AM

<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 


#5 Biggles

Biggles

    Advanced Member

  • Salty Members
  • 984 posts
  • LocationNew Zealand

Posted 03 March 2012 - 05:59 AM

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.

#6 Madolah

Madolah

    ;Wyrm

  • Salty Members
  • 2035 posts
  • LocationSt.John's , Newfoundland, Canada

Posted 06 March 2012 - 02:00 AM

Got it working after, I couldnt solve the Repeat/Duplicate retrievals from happening, but i got links to work!

Wyrm  | Madolah | ær 





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users