Advanced Search

Results 1 to 3 of 3

Thread: Random Photo Gallery with links

  1. #1
    Join Date
    Jun 2013
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Random Photo Gallery with links

    I am trying to do a photo gallery that will pull from a list of thousands of pics with links to other webpages. I am currently writing a scrript in javascript but wondering if there is another way to do it. In a perfect world i would like to have a database that has the pic name and the link name next to it and the script randomly pull from this list. The list would have to change everyday so that the pics would rotate without repeating.

    Moderator's Note:

    This is loosely a continuation of this old thread:

    http://www.dynamicdrive.com/forums/s...-photo-gallery
    Last edited by jscheuer1; 06-01-2013 at 09:17 AM. Reason: add note

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,694
    Thanks
    43
    Thanked 3,132 Times in 3,096 Posts
    Blog Entries
    12

    Default

    Having a database virtually requires that you use a server side language but could be utilized using AJAX to fetch it and javascript to process it, in which case it would probably be best if the database were an XML file, though a plain text file might be workable.

    Since the thread you originally posted to used PHP, do you have that available? If so, the database could be a server side database, or a plain text file or an XML file.

    I don't work with server side databases much, but if you know how to set up and retrieve data from them, you could do that part. Other than that, I can probably write the modifications/code from scratch, whatever we decide to do depending upon what you have to work with.

    One server side option would be to have a folder with all the images in it. These could be fetched with PHP then shuffled and have the first 20 or however many chosen, and in that same folder could be text files, one for each image that would have the same filename as the image and a .txt extension. Each of these files would contain that image's link and then be fetched to provide that part of the HTML that the server side code would write.

    In all of the other scenarios, all of the images and their links would be listed in the database, text file or XML file, whichever is used. The javascript and/or server side code would pick 20 at random and show the HTML for those.

    However, random means random, the same, or more likely some of the same images would show up each time. If that's not OK, we would need a way to store which images have been shown and/or eliminate them from the pool of images that can be shown until there are not enough left to show, at which point all would be included in the pool again. But from what point of view? Would that be per user (user's perspective), or just a general rotation based upon which images have been shown to anyone (server's perspective)?

    If the former we would want to set and maintain a cookie to tell us what each user has already seen. If the later, we could shift the information from one place to another as it's used and bring it all back once there are not enough entries to populate the page as desired.

    This all seems like a bit of a project to me though. So, once we decide what we want to do and how we want to do it, it might take some time for me to write it.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Jun 2013
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    ****PLEASE EXCUSE THE CONTENT...IT IS ADULT ORIENTED****


    I do have access to use a server side database. It can be in any language. I wrote a little something with a js script. It was the only way i could think of calling the pics since they are links. This is what I have so far, but it doens't seem very stable to me...it seems there is an easier way to do it... Also the pics(links) are being called randomly...i would like them to be called but only change once a day.


    HTML script...

    HTML Code:
    <table>
    						   		  <tr>
    								  	  <td><script>document.write( randomlink() );</script></td>
    									  <td><script>document.write( randomlink() );</script></td>
    									  <td><script>document.write( randomlink() );</script></td>
    									  <td><script>document.write( randomlink() );</script></td>
    								  </tr>
    								  <tr>
    								  	  <td><script>document.write( randomlink() );</script></td>
    									  <td><script>document.write( randomlink() );</script></td>
    									  <td><script>document.write( randomlink() );</script></td>
    									  <td><script>document.write( randomlink() );</script></td>
    								  </tr>
    								  <tr>
    								  	  <td><script>document.write( randomlink() );</script></td>
    									  <td><script>document.write( randomlink() );</script></td>
    									  <td><script>document.write( randomlink() );</script></td>
    									  <td><script>document.write( randomlink() );</script></td>
    								  </tr>
    								  <tr>
    								  	  <td><script>document.write( randomlink() );</script></td>
    									  <td><script>document.write( randomlink() );</script></td>
    									  <td><script>document.write( randomlink() );</script></td>
    									  <td><script>document.write( randomlink() );</script></td>
    								  </tr>
    								   <tr>
    								  	  <td><script>document.write( randomlink() );</script></td>
    									  <td><script>document.write( randomlink() );</script></td>
    									  <td><script>document.write( randomlink() );</script></td>
    									  <td><script>document.write( randomlink() );</script></td>
    								  </tr>
    						   </table>

    and this is the external .js scirpt...

    Code:
    var randomlinks=new Array()
     
    
    randomlinks[0]='<a href="http://[...].com/movies/289/?t1/revs=grendel54" target="_blank"><img alt="[...]" src="thumbs/[...].jpg" style="border: 1px solid #BCBCBC"  width="200" height="150"></a>'
    randomlinks[1]='<a href="http://[...].com/movies/290/?t1/revs=grendel54" target="_blank"><img alt="[...]" src="thumbs/[...].jpg" style="border: 1px solid #BCBCBC"  width="200" height="150"></a>'
    randomlinks[2]='<a href="http://[...].com/movies/291/?t1/revs=grendel54" target="_blank"><img alt="[...]" src="thumbs/[...].jpg" style="border: 1px solid #BCBCBC"  width="200" height="150"></a>'
    randomlinks[3]='<a href="http://[...].com/movies/292/?t1/revs=grendel54" target="_blank"><img alt="[...]" src="thumbs/[...].jpg" style="border: 1px solid #BCBCBC"  width="200" height="150"></a>'
    randomlinks[4]='<a href="http://[...].com/movies/293/?t1/revs=grendel54" target="_blank"><img alt="[...]" src="thumbs/[...].jpg" style="border: 1px solid #BCBCBC"  width="200" height="150"></a>'
    randomlinks[5]='<a href="http://[...].com/movies/294/?t1/revs=grendel54" target="_blank"><img alt="[...]" src="thumbs/[...].jpg" style="border: 1px solid #BCBCBC"  width="200" height="150"></a>'
    randomlinks[6]='<a href="http://[...].com/movies/295/?t1/revs=grendel54" target="_blank"><img alt="[...]" src="thumbs/[...].jpg" style="border: 1px solid #BCBCBC"  width="200" height="150"></a>'
    randomlinks[7]='<a href="http://[...].com/movies/296/?t1/revs=grendel54" target="_blank"><img alt="[...]" src="thumbs/[...].jpg" style="border: 1px solid #BCBCBC"  width="200" height="150"></a>'
    randomlinks[8]='<a href="http://[...].com/movies/297/?t1/revs=grendel54" target="_blank"><img alt="[...]" src="thumbs/[...].jpg" style="border: 1px solid #BCBCBC"  width="200" height="150"></a>'
    randomlinks[9]='<a href="http://[...].com/movies/298/?t1/revs=grendel54" target="_blank"><img alt="[...]" src="thumbs/[...].jpg" style="border: 1px solid #BCBCBC"  width="200" height="150"></a>'
    
    function randomlink(){
    var add = randomlinks[Math.floor(Math.random()*randomlinks.length)]
    return(add)
    }

    EXCUSE THE CONTENT IT IS ADULT BASED
    Edit: mod's edit
    Do not post explicit text or URLs to p0rnography.
    I understand that you are not intending to break any rules, and that this is simply the content you are working with, but please be considerate of the fact that this is a site for all ages.

    ...also, you can use [CODE]/* your code goes here */[/CODE] tags to make your code more readable.
    Last edited by traq; 06-10-2013 at 04:35 AM. Reason: obfuscated explicit text and URLs

Similar Threads

  1. Random photo gallery
    By Heatherfly in forum JavaScript
    Replies: 16
    Last Post: 06-01-2013, 02:04 AM
  2. random images in a table plus links
    By keltoid in forum JavaScript
    Replies: 4
    Last Post: 09-23-2010, 06:21 PM
  3. Javascript random im age on refresh with links and targets
    By moose86 in forum Looking for such a script or service
    Replies: 1
    Last Post: 12-13-2009, 03:43 PM
  4. Random Image with Specific Links
    By Sachmet in forum JavaScript
    Replies: 2
    Last Post: 03-09-2009, 10:22 PM
  5. HELP! Random links for download..
    By marikatech in forum HTML
    Replies: 1
    Last Post: 10-01-2005, 09:08 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •