Jump to content


[PHP] use something once?


4 replies to this topic

#1 high6

    Young Padawan

  • Members
  • Pip
  • 57 posts

Posted 17 July 2006 - 11:57 AM

well my goal here is to make a signature that randomly puts in a bunch of images but each image can only be used once. how would i do this(make the image only be choosen once)?

#2 Net-Margin

    Young Padawan

  • Members
  • Pip
  • 55 posts
  • Location:United Kingdom
  • Interests:My main interests would have to be general computing and digital imaging; but I also enjoy Website Design and animation.<br /><br />Away from the computer I enjoy watching Science programs and astronomy.<br /><br />My main skills would have to be XHTML and Web Marketing but I also have good knowledge in CSS, Search Engine Optimization and Javascript.<br /><br />I own the Macromedia Studio 8 which I believe is one of the best packages ever. I also use Visual Basic 2005 Express Edition.

Posted 17 July 2006 - 02:20 PM

Although I think your trying to use GD I don't know if it's still the same as I have never used it but you should look into the array_rand function and store the images in an array. If you don't know what an array is then it's like this.

<?php

	$images array("image","image2","image3");
	
?>

Also to display them for example echo them you would use the array numbers for example $images[0] would be the string image..

I may not be right as I don't use GD. Infact I would bet i'm wrong after slowly looking into bits of GD functions I see it's a bit different..

Edited by Net-Margin, 17 July 2006 - 02:23 PM.


#3 Indigo

    Official Alien

  • Members
  • PipPipPip
  • 617 posts
  • Gender:Male
  • Location:Trondheim, Norway
  • Interests:Computing in general, especially design and programming of all kinds.

Posted 17 July 2006 - 05:38 PM

What about placing all the images in a database, and then extract one at at time? Then, you can set a field in the database to 0 if it's not viewed yet, and to 1 if it's viewed, and extract only the images with value 0.

Another way of doing it could be to give all the images in the database an id, and start with #1 and then add +1 to the ID for each time the page is refreshed.

Just a few ideas, I hope I described well.

#4 NGPixel

    Senior Programmer

  • P2L Staff
  • PipPipPipPip
  • 1,410 posts
  • Gender:Male
  • Location:Montreal, Canada
  • Interests:Web Design : Coding : Animation

Posted 17 July 2006 - 11:30 PM

I would recommend using Sessions so all images can be seen by everyone but not repeated for the same person. But if you want it to be global, then you need to use a database or a file to keep track of displayed images. (better use a file, just think of all the queries...)

#5 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 18 July 2006 - 03:27 PM

I'd load the images into an array, suffle() them, then just use a foreach or for loop to add how ever many of them you want to the "bigger" image.

You could also load the paths to them into a database, and then just select them with the rand() function of mySQL (same concept as an affiliate randomiser), and then loop through the results just as though you used shuffle().

That way, you don't have to do anything complex, and each image will only get used once.

Now, if you mean use each image once period (as in if you refresh the page, it will never show again), then just delete the entry from your database, or delete it from your server (depending on which method you used).





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users